.zIndex()

jQuery

.zIndex()


Contents:

.zIndex() Returns: jQuery

Description: Get the z-index for an element.

  • .zIndex()

    • This method does not accept any arguments.

The .zIndex() method is useful for finding the z-index of an element, regardless of whether the z-index is set directly on the element or on one of its ancestors. In order to determine the z-index, this method will start at the specified element and walk up the DOM until it finds an element that is positioned and has a z-index set. If no such element is found, then the method will return a value of 0.

This method assumes that elements with nested z-indexes would not have a z-index of 0. For example, given the following DOM the inner element will be treated as if it does not have a z-index set because it is impossible to differentiate between an explicit value of 0 and no value in Internet Explorer.

1
2
3
                                
<div style="z-index: -10;">
<div style="z-index: 0;"></div>
</div>

.zIndex( zIndex ) Returns: Integer

Description: Set the z-index for an element.

  • .zIndex( zIndex )

    • zIndex
      Type: Integer
      The z-index to set.

This is equivalent to .css( "zIndex", zIndex ).