Remove All CSS Classes Using jQuery



To remove all classes, use the removeClass() method with no parameters. This will remove all of the item's classes.

Example

You can try to run the following code to remove all CSS classes using jQuery:

Live Demo

<html>
   <head>
      <title>jQuery Selector</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   
      <script>
         $(document).ready(function() {
           $("#button1").click(function(){
             $("p").removeClass();
           });
         });
      </script>
       
      <style>
         .red { color:red; }
         .blue { color:blue; }
      </style>
   </head>
   
   <body>
      <p class = "red" >This is first paragraph.</p>
      <p class = "blue">This is second paragraph.</p>
      <button id="button1">Remove</button>
   </body>
</html>
Updated on: 2019-12-06T10:33:52+05:30

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements