jQuery Miscellaneousindex()Methods
Examples
Get the index of the clicked <li> element relative to its sibling elements:
$("li").click(function(){
alert($(this).index());
});
alert($(this).index());
});
Try it Yourself »
Definition and Usage
The index() method returns the index position of a specified element relative to other specified elements.
These elements can be specified via jQuery selectors or DOM elements.
Note:If the element is not found, index() will return -1.
The index of the first matching element relative to its sibling elements.
Get the index position of the first matching element relative to its sibling elements.
Syntax
The index of the element relative to the selector.
Get the index position of an element relative to a selector.
The element can be specified via a DOM element or a jQuery selector.
Syntax
| Parameters | Description |
|---|---|
| element | Optional. Specifies the element for which to obtain the index position. Can be a DOM element or a jQuery selector. |
Other Extensions
jQuery Miscellaneous Methods