jQuery DOM Element Method - index() Method
Example
Get the name and value of the first p element:
$("li").click(function() { alert($(this).index()); });
Definition and Usage
The index() method returns the index position of the specified element relative to other specified elements.
These elements can be specified by jQuery selector or DOM element.
Note:If the element is not found, index() will return -1.
The index of the first matching element, relative to the sibling element
Get the index position of the first matching element relative to its sibling elements.
Syntax
$(selector).index()
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 DOM element or jQuery selector.
Syntax
$(selector).index(element)
Parameter | Description |
---|---|
element | Optional. Specifies the element to be obtained at the index position. It can be a DOM element or a jQuery selector. |