jQuery [attribute!=value] 選擇器
jQuery 中的 [attribute!=value] 選擇器用於選擇沒有指定屬性和值的每個元素。
語法
語法如下 -
$("[attribute!='value']")示例
現在讓我們看一個示例來實現 jQuery [attribute!=value] 選擇器 -
<!DOCTYPE html>
<html>
<head>
<style>
.one {
color: white;
background-color: orange;
font-size: 16px;
border: 2px blue dashed;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p[class!='demo']").addClass("one");
});
</script>
</head>
<body>
<h1>Car Details</h1>
<p>Car is XUV500</p>
<p class="demo">2179 cc</p>
<p>Independent Suspension</p>
<p>Fuel Tank Capacity: 70 litres</p>
</body>
</html>輸出
這將產生以下輸出 -

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
安卓
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP