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

What is the difference between size() and length in jquery?

青灯夜游
青灯夜游Original
2020-11-13 10:08:192646browse

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.

What is the difference between size() and length in 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 ").length

To 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!

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