Home >Web Front-end >JS Tutorial >What is the difference between jquery size() and length

What is the difference between jquery size() and length

coldplay.xixi
coldplay.xixiOriginal
2020-11-19 11:37:582724browse

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.

What is the difference between jquery size() and 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn