jquery hasClass() method


  Translation results:

has

英[həz] 美[hæz]  

v.Have (the third person singular of have); (in a kinship relationship) accept; take; Buy

class

UK[klɑ:s] US[klæs]

n.Class; class; grade; category

vt. Classify... into a certain level, treat... (or classify, categorize); put... into a certain class

adj. Very good, excellent, outstanding

vi. Belongs to... category (or level) and is listed as a certain category (or level)

jquery hasClass() methodsyntax

Function: hasClass() method checks whether the selected element contains the specified class.

Syntax: $(selector).hasClass(class)

##Parameters:

ParameterDescriptionclass Required. Specifies the class to be found in the specified element.

jquery hasClass() methodexample

<html>
<head>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    alert($("p:first").hasClass("intro"));
  });
});
</script>
<style type="text/css">
.intro
{
font-size:120%;
color:red;
}
</style>
</head>

<body>
<h1 id="h1">This is a heading</h1>
<p class="intro">This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>检查第一个段落是否拥有类 "intro"</button>
</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance