Latest web development tutorials

jQuery miscellaneous index () method

jQuery Misc Methods jQuery Misc Methods

Examples

Obtained is clicked <li> element with respect to the index to its sibling elements:

$("li").click(function(){
alert($(this).index());
});

try it"

Definition and Usage

index () method returns the index position of the specified element with respect to the 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 first element relative to the index matching sibling element.

Get the first matched element relative to its index position of the sibling elements.

grammar

$(selector).index()

try it"


Select the element relative to the index.

Gets the element with respect to the selector index position.

This element can be specified by DOM element or jQuery selector.

grammar

$(selector).index( element )

try it"

参数 描述
element 可选。规定要获得 index 位置的元素。可以是 DOM 元素或 jQuery 选择器。


jQuery Misc Methods jQuery Misc Methods