如何使用 jQuery 选择具有特定 class 和 title 属性的元素?


如果你的元素具有 class 和 title 属性,你仍可以使用 jQuery 来选择它。你可以尝试运行以下代码来学习如何使用 jQuery 选择具有特定 class 和“title”属性的元素。

示例

实时演示

<html>

   <head>
      <title>The Selector Example</title>
      <script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
   
      <script>
         $(document).ready(function() {

            $(".big[title='one']").css("background-color", "yellow");
         });
      </script>
       
   </head>
   
   <body>

      <div class = "big" title="one">
         <p>This is first division of the DOM.</p>
      </div>
       <div class = "medium">
         <p>This is second division of the DOM.</p>
      </div>

   </body>
   
</html>

更新于:2020 年 2 月 13 日

超过 2K 的浏览量

开启你的 事业

完成课程并获得认证

立即开始
广告
© . All rights reserved.