Javascript examples for jQuery Method and Property:length
The length property returns the number of elements in the jQuery object.
The following code shows how to Alert the number of <li> elements:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ console.log($("li").length); });/*from w ww. j a va2s . co m*/ }); </script> </head> <body> <button>Alert the number of li elements</button> <ul> <li>A</li> <li>B</li> <li>C</li> </ul> </body> </html>