How does jquery determine the number of the current element
This article mainly explains "how to judge the current element by jquery". Friends who are interested may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to determine the number of current elements by jquery.
Jquery method to determine the current element is: 1, create a HTML example file; 2, through the jQuery code "$(" ul li ") .click (function () {var index = $(" ul li "). Index...})" can be judged.
This article operating environment: windows7 system, jquery3.2.1 version, DELL G3 computer
How does jquery determine the number of the current element?
Suppose you have a piece of HTML code like this:
JQuery determines the number of elements the current element is example jQuery gets the Nth element example jQuery selector example
JQuery determines which element the current element is.
If we click on any of the li tags and want to know which li tag we are clicking on, we can use the following code:
$("ul li") .click (function () {var index = $("ul li") .index (this); alert (index);})
Such as the above jQuery code, if the first click will prompt "0", if it is the second li tag will prompt "1", note that the index serial number starts at 0.
At this point, I believe you have a deeper understanding of "how to judge the current element by jquery". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!