Tutorials Exercises Get Certified Services Menu
Log in
Sign Up Spaces Bootcamps

jQuery offsetParent() Method

❮ jQuery Traversing Methods


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

  $("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).



❮ jQuery Traversing Methods