Example of jQuery object length attribute usage, jquerylength
This document describes the usage of the length attribute of a jQuery object. Share it with you for your reference. The specific analysis is as follows:
This attribute returns the number of objects in the matching jQuery object set.
The length attribute returns the same value as the size () method.
Syntax structure:
Copy codeThe Code is as follows: $ ("selector"). length
Instance code:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "UTF-8">
<Meta name = "author" content = "http://www.bkjia.com/"/>
<Title> helping customers </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"). length );
})
});
</Script>
</Head>
<Body>
<Div>
<Ul>
<Li> background area </li>
<Li> foreground area </li>
<Li> database zone </li>
<Li> webmaster communication </li>
</Ul>
</Div>
<Div> Number of li elements in the li Element Set: <span> </div>
<Button id = "btn"> click to view instances </button>
</Body>
</Html>
The preceding Code obtains the number of li elements in the li element set through the length attribute.
I hope this article will help you with jQuery programming.