Is there any difference between $(".selector").size()
and $(".selector").length
?
The size() method returns the number of elements matched by the jQuery selector.
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()
The length property is used to count number of the elements of the jQuery object. where selector is the object whose length is to be calculated. Return Values: It returns the length of the selector.
$ sign is just a valid javascript identifier which is used as an alias for jQuery. Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function). Most of them also have a way to relinquish the $ so that it can be used with another library that uses it.
No. size()
returns length
. By using length
you only avoid one extra method call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With