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
Release: 2020-11-19 11:37:58
Original
2713 people have browsed it

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()
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template