Usage Analysis of index () in jQuery, jqueryindex
This document describes the usage of index () in jQuery. Share it with you for your reference. The specific method is as follows:
Now there is a problem: if there are more than N list items in the list, I want to know which one should I click?
In this regard, jQuery provides an index () method:
index(subject)
This method searches for elements that match the object indicated by parameters and returns the index value of the corresponding element.
If a matching element is found, return from 0; if no matching element is found, return-1.
However, the example provided in the API does not seem to be correct. The example is as follows:
<Ul> <li> <a href = "# nogo"> here is a sequence </a> </li> <a href = "# nogo"> here is a sequence </a> </li> <a href = "# nogo"> here is a sequence </a> </li>
As shown above, this is an unordered list. How can I click any list project to obtain the project sequence?
The implementation method is as follows:
$(document).ready(function(){ $("#act li").click(function(){ alert( $( "#act li" ).index( $(this)[0] ) ); })})
Here:
$( "#act li" ).index( $(this)[0] )
Very important!
Jquery index () Usage
Do not repeat the id of td.
The detailed usage of jquery index, how does jquery retrieve the index?
// 1. Pass a DOM object and return the index position of this object in the original set $ ('lil '). index ($ ('# bar'); // 1, passing a jQuery object $ ('lil '). index ($ ('li: gt (0) '); // 1, passing a set of jQuery objects, returns the index position of the first element in this object in the original set $ ('# bar '). index ('lil'); // 1. Pass a selector and return # position of bar in all li. // 1. No parameter is passed, returns the index position of this element in the same generation.