index

UK[ˈɪndeks] US[ˈɪnˌdɛks]

n.index;<number>index;indication;sign

vt. Index...; Index...; [Economics] Adjust according to living index (wages, prices, etc.)

vi.[Mechanics] Transposition

jquery index() method syntax

Function: index() method returns the index position of the specified element relative to other specified elements. These elements can be specified via jQuery selectors or DOM elements. If the element is not found, index() will return -1.

The index of the first matching element is equivalent 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, equivalent to the selector: Get the element relative to The index position of the selector. The element can be specified via a DOM element or a jQuery selector.

Syntax: $(selector).index(element)

##Parameters:

ParameterDescriptionelement Optional. Specifies the element to obtain the index position. Can be a DOM element or a jQuery selector.

jquery index() method example

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("li").click(function(){
    alert($(this).index());
  });
});
</script>
</head>
<body>
<p>点击列表项可获得其相对于同胞元素的 index 位置:</p>
<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance