.offsetParent()
In this chapter you will learn:
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">//from ja va 2s . c o m
<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>
</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
$('li.item-a').offsetParent().css('background-color', 'red');
marks item II.
Next chapter...
What you will learn in the next chapter: