Home >>jQuery Tutorial >jQuery hasClass() Method

jQuery hasClass() Method

jQuery hasClass() Method

jQuery hasClass() method is used to checks if any of the selected elements have a specified class name. It return "true" if the.

Syntax:
$(selector).hasClass(classname)

Parameter Values

Parameter Description
classname It is a required parameter and is used to Specifies the class name to search in the selected elements
Here is an Example of jQuery hasClass() Method:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
alert($(".phptpoint").hasClass("phptpoint"));
});
});
</script>
<style>
.phptpoint {
font-size: 120%;
color: blue;
}
</style>
</head>
<body>
<h1>Phptpoint</h1>
<p class="phptpoint">This is a phptpoint.</p>
<p>Hello world</p>
<button class="btn1">click me to check class</button>
</body>
</html>

Output:

Phptpoint

This is a phptpoint.

Hello world


No Sidebar ads