.offsetParent()

In this chapter you will learn:

  1. Syntax and Description for .offsetParent()

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:

  1. Syntax and Description for .outerHeight() method
  2. How to get the out height of a div element