Example of hasClass () method usage in jQuery, jqueryhasclass
This document describes the usage of the hasClass () method in jQuery. Share it with you for your reference. The specific analysis is as follows:
This method verifies whether the matching element contains the specified class. If the matching element contains the specified class, true is returned. Otherwise, false is returned.
Syntax structure:
Copy codeThe Code is as follows: $ (selector). hasClass (class)
Parameter List:
| Parameters |
Description |
| Class |
The name of the matched class. |
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>
<Script type = "text/javascript" src = "mytest/jQuery/jquery-1.8.3.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
Alert ($ ("li"). hasClass ("js "))
})
</Script>
</Head>
<Body>
<Div>
<Ul>
<Li> HTML zone </li>
<Li class = "js"> Javascript area </li>
<Li> Div + Css area </li>
<Li> Jquery area </li>
</Ul>
</Div>
</Body>
</Html>
The code above can pop up a Boolean value to show whether the detected class property value exists.
I hope this article will help you with jQuery programming.