Home >Web Front-end >JS Tutorial >How to determine which element the current element is in jquery
How jquery determines which element the current element is: 1. Create an HTML sample file; 2. Use the jQuery code "$("ul li").click(function () {var index = $( "ul li").index...})" can be used to judge.
The operating environment of this article: windows7 system, jquery version 3.2.1, DELL G3 computer
How does jquery determine the order of the current element? indivual?
Suppose there is the following HTML code:
<ul> <li>jQuery判断当前元素是第几个元素示例</li> <li>jQuery获取第N个元素示例</li> <li>jQuery选择器示例</li> </ul>
jQuery determines which element the current element is
If we click on any li tag, we want to know the current To determine which li tag is clicked, you can use the following code:
$("ul li").click(function () { var index = $("ul li").index(this); alert(index); });
Such as the jQuery code above, if the first one is clicked, "0" will be prompted, if it is the second Each li tag will prompt "1". Note that the index sequence number starts from 0.
Recommended learning: "jquery video tutorial"
The above is the detailed content of How to determine which element the current element is in jquery. For more information, please follow other related articles on the PHP Chinese website!