jQuery offsetParent()Method

jQuery 遍历方法jQuery Traversing Methods

Examples

Set the background color of the nearest positioned parent element of the <p> element:

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

Try it Yourself »

Definition and Usage

The offsetParent() method returns the first positioned parent element.

Tip:Elements can be positioned via jQuery or the CSS position property (relative, absolute, or fixed).


Syntax

$(selector).offsetParent()


jQuery 遍历方法jQuery Traversing Methods

Other Extensions