jQuery not() 方法示例
jQuery 中的 not() 方法用於返回不匹配特定條件的元素。
語法
語法如下 −
$(selector).not(criteria,func(index))
其中,criteria 是一個選擇器表示式,而 func 是為該組中的每個元素執行的函式。
示例
現在,讓我們看一個實現 jQuery not() 方法的示例 −
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h2").not(".demo").css("color", "orange");
});
});
</script>
<style>
h2 {
color: blue;
}
</style>
</head>
<body>
<h2>Student Info</h2>
<p>This is a demo text.</p>
<h2 class="demo">Exam Info</h2>
<p>This is a demo text.</p>
<h2 class="demo">Teacher's Info</h2>
<p>This is a demo text.</p>
<button>Click me</button>
</body>
</html>輸出
這將產生以下輸出 −

現在,單擊“單擊我”以更新不符合特定條件的元素的文字顏色 −

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP