Alert the number of <li> elements:
<!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 = $("li").length; });// w w w . j a v a2 s .c o m }); </script> </head> <body> <p id="demo"></p> <button>Alert the number of li elements</button> <ul> <li>CSS</li> <li>HTML</li> <li>Javascript</li> </ul> </body> </html>
The length property contains the number of elements in the jQuery object.
$(selector).length