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