jQuery .offsetParent() gets the closest positioned ancestor element
Syntax and Description
.offsetParent()
gets the closest positioned ancestor element. Return value is the new jQuery object.
Consider a page with a basic nested list with a positioned element as follows:
<ul class="level-1">
<li class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
</ul>/*from ww w . j av a2 s.c om*/
</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
$('li.item-a').offsetParent().css('background-color', 'red');
marks item II.