Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery offsetParent() method

jQuery offsetParent() method

jQuery Traversal Methods jQuery Traversal Methods

Example

Settings

the background color of the nearest positioned parent element of the.

$("button").click(function(){

$("p").offsetParent().css("background-color","red");

});

Try it »


Definition and Usage

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

**Tip:** An element can be positioned via the position property in jQuery or CSS (relative, absolute, or fixed).


Syntax

$(

selector

).offsetParent()


jQuery Traversal Methods jQuery Traversal Methods