The jquery attribute method Hasclass Determine if there is a class

Source: Internet
Author: User

Determines whether there is at least one element in the matching collection using the style 'selected', the presence returns ' true ' and does not exist as ' flase '.

<HTML>  <Head>  <Scriptsrc= "Http://code.jquery.com/jquery-latest.js"></Script>  <Script>$ (document). Ready (function(){  $("DIV#RESULT1"). Append ($ ("P:first"). Hasclass ("selected"). toString ()); $("DIV#RESULT2"). Append ($ ("P:last"). Hasclass ("selected"). toString ()); $("DIV#RESULT3"). Append ($ ("P"). Hasclass ("selected"). toString ());  }); </Script>  <style>P{margin:8px;font-size:16px; }. Selected{Color:Red; }. Highlight{background:Yellow; }  </style>  </Head>  <Body>  <P>Hello</P>  <Pclass= "Selected">Goodbye</P>  <DivID= "RESULT1">First paragraph has selected class:</Div>  <DivID= "RESULT2">Last paragraph have selected class:</Div>  <DivID= "RESULT3">Some paragraph has selected class:</Div>  </Body>  </HTML>

$ ("Div#result1"). Append ($ ("P:first"). Hasclass ("selected"). toString ());
$ ("Div#result2"). Append ($ ("P:last"). Hasclass ("selected"). toString ());
$ ("Div#result3"). Append ($ ("P"). Hasclass ("selected"). toString ());
The first line determines whether the first P element in the P collection uses the ' selected ' style.
The second line determines whether the last P element in the P collection uses the ' selected ' style.
The first line determines whether each P element in the P collection has at least one using the ' selected ' style.

The jquery attribute method Hasclass Determine if there is a class

Related Article

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.