How many jquery can get li?
This article introduces the relevant knowledge of "how to obtain li by jquery". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
In jquery, you can use the index () method to get the number of the specified li. This method is used to return the index position of the specified element relative to other specified elements. Adding the obtained index value is the value of the specified element. The syntax is "li element object .index () + 1".
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
How many does jquery get li?
In jquery, you can use the index () method to get the position of the li tag currently clicked.
Create a new html file, named test.html, to explain how to use jquery to know which li I clicked on.
Load the jquery.min.js file using the script tag, and load the file successfully before you can use the jquery method.
Use the ul tag, the li tag to create a list, for example, to create three project lists. Use the ready () method to execute the function method when the page is loaded.
Within the function method, by getting the li object, each li is bound to a click click event using the bind () method. When the li is clicked, the index value of the current li tag is obtained by the index () method, and finally, the index value is output using the alert () method.
Open the test.html file in the browser and click the button to view the results.
This is the end of the content of "how to get li from jquery". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!