Easy Tutorial
❮ Sel Odd Sel Parent Child ❯

jQuery offsetParent() Method

jQuery HTML/CSS Methods

Example

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

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

Definition and Usage

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

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


Syntax


jQuery HTML/CSS Methods

❮ Sel Odd Sel Parent Child ❯