How to use hasClass() method in jQuery?

jQueryWeb DevelopmentFront End Technology

The hasClass() method is used to check if an element has a class. You can try to run the following code to learn how to use hasClass() method in jQuery −


Live Demo

<!DOCTYPE html>
      <script src=""></script>
         .myclass {
           color: blue;
      <h1 class="myclass">Heading</h1>
      <p>This is demo text.</p>
      <button>Check: The h1 element has 'myclass' class?</button>
Updated on 14-Feb-2020 05:26:57