Jquery determines how many li there are in ul: 1. Get the li element object under the specified ul, the syntax is "$("ul li")"; 2. Use the length attribute to get the li element object Quantity, the function of this attribute is to obtain the number of elements contained in the jQuery object. The syntax is "li element object.length".
The operating environment of this tutorial: windows10 system, jquery3.4.1 version, Dell G3 computer.
1. Get the li element object
The syntax is:
$("ul li")
2. Get the number based on the element object
The length property contains the number of elements in the jQuery object.
Syntax
$(selector).length
The example is as follows:
123 <script> $(document).ready(function(){ $("button").click(function(){ alert($("ul li").length); }); }); </script>
Output result:
After clicking the button:
Video tutorial recommendation: jQuery video tutorial
The above is the detailed content of How does jquery determine how many li there are in ul?. For more information, please follow other related articles on the PHP Chinese website!