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>
Published on 15-Dec-2017 10:15:00