Home > Article > Web Front-end > How to get how many li there are in jquery
How to get the number of li in jquery: 1. Create an HTML sample file; 2. Introduce the jquery library; 3. Get the li through the "$("#questionUl li").length;" method.
The operating environment of this article: Windows 7 system, jquery version 3.2.1, DELL G3 computer
How to get how many li there are in jquery?
JS/Jquery gets how many li tags there are under the current UL tag
<ul class="zxdy" id="questionUl"> <li >1</li> <li >2</li> <li >3</li> <li >4</li> </ul>
1. js method
<script> var temp = document.getElementById('questionUl'); var linum = temp.getElementsByTagName("li").length </script>
2.jQuery method
var lengli = $("#questionUl li").length;
Recommended learning: "jquery video tutorial"
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!