Jquery Tutorial-jquery Get the number of tags size () function usage

Source: Internet
Author: User

jquery Tutorial-jquery Get the number of tags size () function usage, and the size () method returns the number of elements that are matched by the Jquery selector.

Grammar
$ (selector). Size ()
The number of elements in the JQuery object. The return value of this function is associated with the JQuery object's 'The length ' property is consistent.

Purpose: Can be used to count the number of items in a page. For example, to statistical language scores of less than 100 records, you can give less than 100 of the field assigned to <font class= "xx" >oo</font>. The number of this label is counted as the result.

<Script language="Javascript"Type="Text/javascript"Src="Jquery.min.js"></Script>
<Script language="Javascript"Type="Text/javascript">
$ (document). Ready (function(){
$(‘#sbt‘). Click (function(){
VarI=$(‘Div‘). Size ();//Get the number of div tags
VarJ=$(‘. mm‘). Size ();//Get the number of font labels class mm
$(‘#myspan‘). HTML (‘<strong><font Color=red> altogether has‘+I+‘A div tag &nbsp;&nbsp; altogether has‘+J+‘A font label </font></strong>‘);
})
})

</Script>
<Div>Div1</Div><br>
<Div>Div2</Div><br>
<Div>Div3</Div><br>
<Div>Div4</Div><br>
<Font class="Mm">Mm1</Font><br>
<Font class="Mm">mm2</Font><br>
<Font class="Mm">mm2</Font><br>
<Span ID= "myspan" ></span><br>
<input  Type=submit " value=" calculate " id= "sbt"/>

Jquery Tutorial-jquery Get the number of tags size () function usage

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.