Home > Web Front-end > JS Tutorial > body text

How to get how many li there are in jquery

藏色散人
Release: 2021-11-17 11:00:57
Original
2837 people have browsed it

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.

How to get how many li there are in jquery

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>
Copy after login

1. js method

<script>
 
  var temp = document.getElementById(&#39;questionUl&#39;);
  var linum = temp.getElementsByTagName("li").length
 
</script>
Copy after login

2.jQuery method

var lengli = $("#questionUl li").length;
Copy after login

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!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!