如何使用 jQuery 刪除所有 CSS 類?


若要刪除所有類,請在 removeClass() 方法中不設定任何引數。這將刪除該項的所有類。

示例

你可以嘗試執行以下程式碼,使用 jQuery 刪除所有 CSS 類

即時演示

<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>

更新於: 2019 年 12 月 6 日

5 千+ 瀏覽量

開啟你的職業

完成課程獲得認證

開始
廣告