jQuery offsetParent()Method

jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Example

Set the background color of the nearest positioned ancestor 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 ancestor element.

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


Syntax

$(selector).offsetParent()


jQuery HTML/CSS 方法jQuery HTML/CSS Methods

Other Extensions