offsetParent()

本页内容
上一节: Css_offset 下一节: Html_outerheight

jQuery offsetParent() 方法

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

上一节: Css_offset 下一节: Html_outerheight
此页面最后编辑于2022年8月19日 (星期五) 11:44。