The not()
method negates the selection.
$(selector).not(criteria,function(index))
Parameter | Optional | Description |
---|---|---|
criteria | Optional. | a selector expression, a jQuery object or one or more elements to be removed To specify multiple criteria, use comma. |
function(index) | Optional. | a function to run for each element in a group. If it returns true, the element is removed. Otherwise, the element is kept. index - The index position of the element in the set |
Return all <p> elements that do not have the class name "intro":
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("p").not(".intro").css("background-color", "yellow"); });/*from ww w. ja va 2 s . c o m*/ </script> </head> <body> <h1>Welcome to My Homepage</h1> <p>This is a test.</p> <p class="intro">I am from java2s.com.</p> <p class="intro">CSS HTML.</p> <p>This is another test.</p> </body> </html>