如何在 jQuery 選擇器中使用 .not()?
.not() 用於選擇除某個元素以外的所有 <p> 元素,該元素可以指定。
示例
你可以嘗試執行以下程式碼,瞭解如何在 jQuery 選擇器中使用 .not() 。
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:not(.myclass)").css("background-color", "red");
});
</script>
</head>
<body>
<h1>Heading</h1>
<p class="myclass">This is demo text.</p>
<p>This is another text.</p>
</body>
</html>
廣告
資料結構
網路知識
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP