The index of the element, relative to the selector
Gets the index position of the element relative to the selector.
The element can be specified by a DOM element or JQuery selector.
Grammar
$ (selector). Index (element)
$ (". Hot"). Index ($ ("#favorite")) #favorite相对于指定于其他 the location of hot
<meta charset= "Utf-8" >
<title> Rookie Tutorial (runoob.com) </title>
<script src= "Http://cdn.static.runoob.com/libs/jquery/1.10.2/jquery.min.js" >
</script>
<script>
$ (document). Ready (function () {
$ ("button"). Click (function () {
Alert ($ (". Hot"). Index ($ ("#favorite")));
});
});
</script>
<body>
<p> Click the button to get the index of the element with id = "favorite", relative to the jquery selector (class = "hot"):</p>
<button> Get subscript </button>
<ul>
<li>Milk</li>
<li class= "Hot" >Tea</li>
<li class= "Hot" >Tea</li>
<li >Tea</li>
<li class= "Hot" id= "favorite" >Coffee</li>
</ul>
</body>
JQuery DOM Element Method-Index () method