Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:49:15
Original
1150 people have browsed it

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




Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template