How to solve the problem that size can't be used in jquery
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!