- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
jQuery length property
The length property in jQuery is used to get the number of elements in the jQuery object.
Syntax
The syntax is as follows −
$(selector).length
Example
Let us now see an example to implement the jQuery length property −
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ document.getElementById("demo").innerHTML = "<br>Count = " + $("li").length }); }); </script> </head> <body> <h2>Devices</h2> <ol> <li>TV</li> <li>Laptop</li> <li>Headphone</li> <li>Earphone</li> <li>SSD</li> </ol> <button>Count of li</button> <p id="demo"></p> </body> </html>
Output
This will produce the following output −
Click “Count of li” to get the number of li elements −
Advertisements