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.


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:





        body {
            cursor: pointer;
            min-height: 100px;
        div {
            width: 50px;
            height: 30px;
            margin: 5px;
            float: left;
            background: green;
        span {
            color: black;
    <!-- jQuery code to show the working of this method -->
            .click(function() {
                var n = $("div").size();
                $("span").text("There are " + n + " divs. Click to add more.");
        // Trigger the click to start


Before clicking on the screen-

After clickiing three times on the screen-

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.