Example of jQuery object length attribute usage, jquerylength

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.