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>

輸出

這將產生以下輸出 -

更新於: 11-11-2019

440 次瀏覽

開啟你的 事業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.