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 方法

0 个评论

要回复文章请先登录注册