Javascript examples for jQuery Selector:attribute not have
The [attribute!=value] selector selects elements who do not have the attribute and value pair.
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":
<!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>