jQuery Miscellaneous index() method
Example
Get the index of the clicked
$("li").click(function(){
alert($(this).index());
});
Try it »
Definition and Usage
The index() method returns the index position of a specified element relative to other specified elements.
These elements can be specified by a jQuery selector or a DOM element.
**Note:** If no element is found, index() returns -1.
The index of the first matched element relative to its siblings.
Get the index position of the first matched element relative to its siblings.
Syntax
$(
selector
).index()
Try it »
The index of the element relative to the selector.
Get the index position of the element relative to the selector.
The element can be specified by a DOM element or a jQuery selector.
Syntax
$(
selector
).index(
element
)
Try it »
| Parameters | Description |
|---|---|
| element | Optional. Specifies the element whose index position is to be obtained. It can be a DOM element or a jQuery selector. |
jQuery Miscellaneous Methods