Difference: 1. size() is a function provided by jQuery, and length is a property. 2. Size() is a method for operating object instances. It is defined in jQuery and can only be used under jQuery; length is defined in dom and javascript and can be used without jQuery.
[Related recommendations: jQuery video tutorial】
size() method returns the elements matched by the jQuery selector quantity.
The length property contains the number of elements in the jQuery object.
The difference between size() and length in jquery
size() is a function provided by jQuery, and length is an attribute (without brackets).
size() is a method for operating object instances. It is defined in jQuery and can only be used under jQuery; length is a property, defined in dom and javascript, and can be used without jQuery.
For tag object elements, for example, counting how many paragraph elements there are in the html page
, then $("p").size()==$("p ").lengthTo calculate the length of a string or the number of elements in an array, you can only use length instead of size()
Explanation:
.size() This method does not accept any parameters. The
.size() method has been deprecated since jQuery 1.8. Use the .length property instead.
For more programming-related knowledge, please visit: Programming Learning Website! !
The above is the detailed content of What is the difference between size() and length in jquery?. For more information, please follow other related articles on the PHP Chinese website!