In this article we will explain how to use hasClass() in jQuery or why use hasClass() in jQuery or how to check class name exists or not in selected element  with example.


The jQuery hasClass() method is used to check whether selected elements have exists class name or not. It returns TRUE if the exists class is present in any of the selected elements otherwise it returns FALSE.



Let’s see, Example of jQuery hasClass() method:

<!DOCTYPE html>
<html xmlns="">
    <title>Example of jQuery remove method</title>
    <script type="text/javascript" src=""></script>
        $(document).ready(function () {
            $("button").click(function () {
    <p class="myclass">This is a paragraph where exists class.</p>
    <p>This is also a paragraph.</p>
    <button>Click here to check if any p element have an "myclass" class?</button>

 Let's check live example

Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like