Home > Web Front-end > JS Tutorial > How to get how many li there are in jquery

How to get how many li there are in jquery

WBOY
Release: 2021-11-17 16:23:12
Original
4050 people have browsed it

Jquery method to get how many li there are: 1. Use the "$('li')" statement to get the li object; 2. Use the length attribute to calculate the length of the obtained li object, and you can get the li in the document. The number of elements, the syntax is "li object.length;".

How to get how many li there are in jquery

The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.

How to get how many li's there are in jquery

1. Create a new html file and name it test.html to explain how to get it in jquery The number of li under ul. Use the ul tag to create a list of items for testing. Add a class attribute to the ul tag to obtain the ul object.

Use the button tag to create a button, bind the onclick event to the button, and when the button is clicked, execute the getLength() function.

How to get how many li there are in jquery

2. Create the getLength() function. Within the function, obtain the li object through class, use the length attribute to obtain the number of li, and use the alert() method to obtain the li object. Number output.

How to get how many li there are in jquery

Open the test.html file in the browser, click the button to view the results.

How to get how many li there are in jquery

Summary:

1. Use the ul tag to create a list of items, and add a class attribute to the ul tag to obtain the ul object.

2. Use the button tag to create a button, bind the onclick event to the button, and when the button is clicked, execute the getLength() function.

3. In the js tag, create the getLength() function. Within the function, obtain the li object through class, use the length attribute to obtain the number of li, and use the alert() method to output the obtained number.

For more programming related knowledge, please visit: Programming Video! !

The above is the detailed content of How to get how many li there are in jquery. For more information, please follow other related articles on the PHP Chinese website!

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