jQuery offsetParent() 方法
示例
設定 <p> 元素最近的已定位父元素的背景顏色
$("button").click(function(){
$("p").offsetParent().css("background-color", "red");
});
自己動手試一試 »
定義和用法
offsetParent() 方法返回第一個已定位的父元素。
提示:可以使用 jQuery 或 CSS position 屬性(relative、absolute 或 fixed)對元素進行定位。
語法
$(selector).offsetParent()