jQuery :not() 選擇器


jQuery 中的 :not 選擇器用於選擇除指定元素之外的所有元素。

語法

語法如下 −

$(":not(selector)")

在上面,設定要忽略(不選擇)的元素。

範例

現在讓我們看一個範例來實現 jQuery :not 選擇器 −

<!DOCTYPE html>
<html>
<head>
<style>
   .one {
      color: white;
      background-color: green;
      font-size: 16px;
      border: 2px blue solid;
   }
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("p:not(.demo)").addClass("one");
   });
</script>
</head>
<body>
<h1>Match Details</h1>
<p class="demo">Date: 29th October 2019</p>
<p>Timings: 3PM TO 8PM</p>
<p>Ground: Lords</p>
</body>
</html>

輸出

這將生成以下輸出 −

更新於:05-11-2019

89 次瀏覽

開始你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.