jQuery offsetParent() 方法

jQuery 遍曆方法 jQuery 遍曆方法

實例

設置 <p> 元素的最近的被定位的父元素的背景顏色:

$("button").click(function(){
$("p").offsetParent().css("background-color","red");
});


定義和用法

offsetParent() 方法返回第一個被定位的父元素。

提示:元素可通過 jQuery 或 CSS 的 position 屬性(relative、absolute 或 fixed)來定位。


語法

$(selector).offsetParent()


jQuery 遍曆方法 jQuery 遍曆方法