jQuery Tutorial Tutorials - jQuery .not() method

jQuery .not() method

The .not() method in jQuery is used to filter out some elements from the set of matched elements.

jQuery .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)

example

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" );

Try now

.not(elements)

Removing Specific Elements

example

$( "p" ).not( document.getElementsByClassName( "selected" ) )
        .css( "background-color", "red" );

Try now

Date:2019-08-26 14:02:01 From:www.Lautturi.com author:Lautturi