Home > Article > Web Front-end > What is the difference between jquery size() and length
The difference between jquery size() and length: 1. Length is an attribute. You can only use length to calculate the character length; 2. [size()] method in jQuery, used to get the number of elements, starting from 1 Calculate the array length.
The difference between jquery size() and length:
● length is an attribute
● size () is the method
● To calculate the character length, you can only use length
If you want to get the number of elements, the effect of both is the same, and the value obtained by
$("img").length $("img").size()
is the same Yes, but if you want to get the length of a string, you have to use length. For example,
$("#text").val().length
jQuery length and size() are different. From the above, we can see that size()
is called, and the length attribute Implemented, and after jquery 1.8, length replaced size(); because length does not need to return a function call, it is better.
size()
is a method in jQuery, used to get the number of elements and calculate the array length starting from 1. Only length
can be used to calculate character length. For example:
$("#dataRuleListtbody").find(":checkbox").size(); $("#dataRuleListtbody").find(":checkbox").length
Related free learning recommendations: JavaScript (video)
The above is the detailed content of What is the difference between jquery size() and length. For more information, please follow other related articles on the PHP Chinese website!