Home > Web Front-end > Front-end Q&A > Why can't size be used in jquery?

Why can't size be used in jquery?

WBOY
Release: 2022-05-18 15:04:12
Original
2239 people have browsed it

Because size was abandoned in jquery version 1.8, the size method cannot be used in versions after 1.8; this method can return 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, the syntax is "$().length".

Why can't size be used in jquery?

The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.

Why size cannot be used in jquery

The size() method was deprecated in jQuery version 1.8. Please use the length property instead.

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

Syntax

$(selector).size()
Copy after login

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

Syntax

$(selector).length
Copy after login

The example is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>123</title>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
alert($("li").length);
});
});
</script>
</head>
<body>
<button>输出li的数量</button>
<ul>
<li>Coffee</li>
<li>Milk</li>
<li>Soda</li>
</ul>
</body>
</html>
Copy after login

Output result:

Why cant size be used in jquery?

After clicking the button:

Why cant size be used in jquery?

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of Why can't size be used in jquery?. 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