jquery Gets the index value of the element indexed () method:
The index () method of jquery searches for a matching element and returns the index value of the corresponding element, counting starting at 0.
If you do not pass an argument to the. Index () method, the return value is the position of the first element in the set of jquery objects relative to its sibling element.
If the parameter is a set of DOM elements or jquery objects, the return value is the position of the passed element relative to the original collection.
If the parameter is a selector, then the return value is the position of the original element relative to the selector matching element. Returns-1 if no matching element is found.
Copy Code code as follows:
<ul>
<li id= "foo" >foo</li>
<li id= "Bar" >bar</li>
<li id= "Baz" >baz</li>
</ul>
$ (' li '). Index (document.getElementById (' Bar ')); 1, passing a DOM object that returns the index position of the object in the original collection
$ (' li '). Index ($ (' #bar ')); 1, passing a jquery object
$ (' li '). Index ($ (' li:gt (0) ')); 1, passing a set of jquery objects that returns the index position of the first element of the object in the original collection
$ (' #bar '). Index (' Li '); 1, pass a selector, return #bar position in all Li
$ (' #bar '). index (); 1, does not pass the parameter, returns the index position of this element in the sibling.
jquery get element index value () example
Copy Code code as follows:
//for level two or three linkage
<div id= "nav" >
<a href= "http://www.51x" uediannao.com/"> Station material </a>
<a href=" http://www.51xuediannao.com/">jquery special effects </a>
<a href= "http://www.51xuediannao.com/" > Lazy host </a>
<a href= "http://www.51xuediannao.com/qd63/" > Front Road </a>
</div>
$ ("#nav a"). Click (function () {
//Four classic usage
var index1 = $ ("#nav a" "). Index (this);
var index2 = $ ("#nav a"). Index ($ (this));
var index3 = $ (this). Index ()
var index3 = $ (this). Index ("a")
Alert (INDEX3);
return false;
});