Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem that size can't be used in jquery

Shulou Source: shulou.com Published: 2022-05-31 16:50:02 10月01日 Update

This article mainly explains "how to solve the problem of size in jquery". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how to solve the problem of size in jquery" together.

Because size was deprecated in version 1.8 of jquery, the size method cannot be used in versions after 1.8; it returns the number of elements matched by the jquery selector and can be replaced by the length attribute, which contains the number of elements in the jquery object, with the syntax "$().length."

Operating environment for this tutorial: Windows 10 system, jquery version 3.2.1, Dell G3 computer.

Why not use size in jquery?

The size() method was deprecated in jQuery version 1.8. Use the length attribute instead.

The size() method returns the number of elements matched by the jQuery selector.

syntax

$(selector).size()

The length property contains the number of elements in the jQuery object.

syntax

$(selector).length

Examples are as follows:

123$(document).ready(function(){$("button").click(function(){alert($("li").length);});}); output the number of li CoffeeMilkSoda

Output:

After clicking the button:

Thank you for reading, the above is "jquery size can not be used to solve" the content, after the study of this article, I believe that we can not use jquery size to solve this problem has a deeper experience, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Tags: Elements attributes methods versions quantity grammar learning content objects number output selection that is ideas situations buttons tutorials articles more environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS OPPO Reno Apple vpn