The size()
method in jQuery is used to find the number of elements that match the given jQuery selector.
$(selector).size();
This method doesn’t accept parameters.
This method returns the number of elements that match the given jQuery selector.
Let’s look at an example of the size()
method in the code snippet below:
In the HTML tab:
div
.jQuery
script.Note: We import the older version.
In the JavaScript tab:
size()
method to count the number of div
.numberOfDivs
on the console.The size()
method counts the number of elements that match the selector div
and output the result to the console.
Note: This method was deprecated in the jQuery version ^1.8 and was removed in the jQuery version ^3.0.