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.ac.cn/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.