Please note, this is a STATIC archive of website www.w3schools.com from 05 May 2020, cach3.com does not collect or store any user information, there is no "phishing" involved.
THE WORLD'S LARGEST WEB DEVELOPER SITE

jQuery offsetParent() Method

❮ jQuery HTML/CSS Methods

Example

Set the background color of the closest 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: An element can be positioned with jQuery, or with the CSS position property (relative, absolute, or fixed).


Syntax

$(selector).offsetParent()

❮ jQuery HTML/CSS Methods