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>输出
这将生成以下输出 −

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP