[attribute!=value] selector selects elements who do not have the attribute and value pair. - Javascript jQuery Selector

Javascript examples for jQuery Selector:attribute not have

Description

The [attribute!=value] selector selects elements who do not have the attribute and value pair.

Syntax

Parameter Description
attribute Required. attribute to match
value Required. value to find

The following code shows how to select all <p> elements that do not have a class attribute with the value "test":

Demo Code

ResultView the demo in separate window

<!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[class!='test']").css("background-color", "red");
});//from ww  w  .j  a v  a2s .c o  m
</script>
</head>
<body>

<h1>Welcome to My Homepage</h1>

<p class="test">This is a test.</p>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>

Who is your favourite:
<ul id="choose">
  <li>A</li>
  <li>B</li>
  <li>C</li>
</ul>

</body>
</html>

Related Tutorials