如何在 jQuery 中使用多個類選擇一個元素?


要使用多個類來選擇一個元素,請執行以下操作。這裡,x、y 和 z 是我們的類,

$('.x.y.z')

你可以嘗試執行以下程式碼,來學習如何在 jQuery 中使用多個類選擇一個元素

現場演示

<html>
   <head>
      <title>jQuery Selector Example</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   
      <script>
         $(document).ready(function() {
            $(".one.two").css("background-color", "grey");
         });
      </script>
   </head>
   
   <body>

      <div class = "one two" id="div">
         <p>This is first division of the DOM.</p>
      </div>

      <div class = "three" id = "div3">
         <p>This is third division of the DOM</p>
      </div>

   </body>    
</html>

更新於: 12-6-2020

602 檢視

開啟你的職業生涯

完成課程取得認證

開始
廣告
© . All rights reserved.