This example describes the use of the size () method in jquery. Share to everyone for your reference. The specific analysis is as follows:
This method can return the number of elements in the JQuery object collection.
The return value of the size () method is consistent with the length property of the jquery object.
Syntax structure:
Copy Code code as follows:
Instance code:
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8" >
<meta name= "Author" content= "http://www.jb51.net/"/>
<title> Cloud-dwelling community </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>
<body>
<div>
<ul>
<li> Backstage </li>
<li> Front Zone </li>
<li> Database Zone </li>
<li> Webmaster Communication </li>
</ul>
</div>
Number of LI elements in the <div>li element collection:<span></span></div>
<button id= "BTN" > Click to view instance </button>
</body>
The above code can calculate the number of LI elements and output.
I hope this article will help you with your jquery programming.