Example of size of method usage in jQuery
- 2020-05-09 18:12:14
- OfStack
This article illustrates the use of the size() method in jQuery as an example. Share with you for your reference. The specific analysis is as follows:
This method returns the number of elements in the collection of jQuery objects.
The return value of the size() method corresponds to the length attribute 1 of the jQuery object.
Grammatical structure:
$(selector).size()
Example code:
<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> The home of the script </title>
<style type="text/css">
span{color:red;}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btn").click(function(){
$("span").text($("li").size());
})
})
</script>
</head>
<body>
<div>
<ul>
<li> The background section </li>
<li> Zone at the front desk </li>
<li> Database zone </li>
<li> Master communication </li>
</ul>
</div>
<div>li In the set of elements li Number of elements :<span></span></div>
<button id="btn"> Click to view an example </button>
</body>
</html>
The code above can count the number of li elements and output them.
I hope this article has helped you with the jquery programming.