jQuery | size() with Examples
The size() is an inbuilt method in jQuery used to find the number of elements matched by the given selector. This method is removed in jQuery 3.0 instead of this length() has been introduced.
Syntax:
$(selector).size()
Parameter: It does not accept any parameters.
Return Value: It returns the number of elements matched by the selected elements.
jQuery code to show the working of size() method:
<html> <head> <style> body { cursor: pointer; min-height: 100px; } div { width: 50px; height: 30px; margin: 5px; float: left; background: green; } span { color: black; } </style> </script> </head> <body> <div></div> <span></span> <!-- jQuery code to show the working of this method --> <script> $(document.body) .click(function() { $(this).append($("<div>")); var n = $("div").size(); $("span").text("There are " + n + " divs. Click to add more."); }) // Trigger the click to start .click(); </script> </body> </html> |
Output:
Before clicking on the screen-

After clickiing three times on the screen-

Recommended Posts:
- How to get the input file size in jQuery ?
- Validation of file size while uploading using JavaScript / jQuery
- How to get the size of screen, current web page and browser window using jQuery?
- jQuery | eq() with Examples
- jQuery | on() with Examples
- jQuery | last() with Examples
- jQuery | has() with Examples
- jQuery | val() with Examples
- jQuery | after() with Examples
- jQuery | first() with Examples
- jQuery | one() with Examples
- jQuery | mousemove() with Examples
- jQuery | prop() with Examples
- jQuery | slideUp() with Examples
- jQuery | noConflict() with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



