The offsetParent method
The offsetParent method allows you to get the closest positioned ancestor of an element. 'positioned' refers to an element with the CSS property position set to relative, absolute, or fixed. This method is useful for animation and when placing elements on a page.
Syntax
Get the closest positioned ancestor:
$(selector).offsetParent();
Example
Let's find the closest positioned (in our case, relatively) ancestor of the paragraph with #test and color its background green:
<div>
<p>aaa</p>
<div style="position: relative;">
<p>bbb</p>
<p>bbb</p>
<p>bbb</p>
<div>
<p id="test">ccc</p>
<div>
<p>ddd</p>
<p>ddd</p>
<p>ddd</p>
</div>
<p>ccc</p>
<p>ccc</p>
</div>
</div>
<p>aaa</p>
<p>aaa</p>
</div>
$('#test').offsetParent().css('background-color', 'green');