jQuery hasClass()

jQuery hasClass() method return true if any of the matched elements have a specified class name.

It will not remove whitespace characters occur in the middle of the string.

Syntax

jQuery.(selector).hasClass(className)

Remove the whitespaces at the start and at the end of the string using jQuery.

HTML
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"> </script>
<title>jQuery hasClass() Example </title>
</head>
<p class="mycssClass">An Example of jQuery hasClass.</p>
<div id="resultDiv"></div>
<button id="myDiv">Check</button>
</html>
Javascript
$(document).ready(function(){
$("#myDiv").click(function(){
if($("p").hasClass("mycssClass"))
{
$("#resultDiv").html('Class found');
}
else
{
$("#resultDiv").html('Class not found');
}
});
});