English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery offsetParent() Method

jQuery HTML/CSS Methods

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

Positioning elements is itsPosition (position)Elements with a value of relative, absolute, fixed, or sticky (except static).

Position elements by using the jQuery or CSS position property (relative, absolute, or fixed).

Syntax:

$("selector").offsetParent()

Example

Set the background color of the closest parent element:

$("document").ready(function(){
  $("li.item-a").offsetParent().css("background-color", "red");
});
Test and See‹/›

jQuery HTML/CSS Methods