jQuery offsetParent() 方法

jQuery HTML/CSS 方法 jQuery HTML/CSS 方法

實例

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

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


定義和用法

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

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


語法

$(selector).offsetParent()


jQuery HTML/CSS 方法 jQuery HTML/CSS 方法