如何使用jQuery删除所有CSS类?

要使用jQuery删除所有CSS类,请使用removeClass()不带参数的方法。

示例

您可以尝试运行以下代码来删除类:

<html>

   <head>
      <title>jQuery Example</title>
      <script src = "https://cdn.staticfile.org/jquery/2.1.3/jquery.min.js"></script>
   
      <script>
         $(document).ready(function() {
            $("p").removeClass();
         });
      </script>
       
      <style>
         .red {
            color:red;
         }
         .green {
            color:green;
         }
      </style>
   </head>
   
   <body>
      <p class = "red" >This is first paragraph.</p>
      <p class = "green">This is second paragraph.</p>
   </body>
   
</html>