Home >Web Front-end >JS Tutorial >Jquery index() method obtains the index value of the corresponding element_jquery

Jquery index() method obtains the index value of the corresponding element_jquery

WBOY
WBOYOriginal
2016-05-16 17:49:151158browse

index([subject]) method, return value: Number (counting from 0)
index() method returns the index position of the specified element relative to other specified elements. Note: index() will return -1 if the element is not found.

Copy code The code is as follows:




< ;script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert($(". hot").index($("#favorite")));
});
});


Please click the button below to get the index of the element with id="favorite" relative to the jQuery selector (class="hot"):


  • Milk

  • Tea

  • Coffee




Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn