.not() methodThe .not() method in jQuery is used to filter out some elements from the set of matched elements.
.not() method Syntax.not(selector) .not(function) .not(selection)
| Parameter | Type | Description |
|---|---|---|
selector |
selector | a selector expression. |
function() |
Function | A function used as a test for every element in the set. |
selection |
jQuery | A jQuery object |
.not(selector)Add a red background for items 2 and 4, as they do not match the selector :even (index is based on 0)
$( "li" ).not( ":even" ).css( "background-color", "red" );
.not(elements)Removing Specific Elements
$( "p" ).not( document.getElementsByClassName( "selected" ) )
.css( "background-color", "red" );
