English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery not() Method

jQuery Traversal Methods

The not() method returns elements that do not meet the specified conditions.

The not() method filters out all elements that match the selected criteria, and unmatched elements will be returned.

The not() method is similar tofilter()The opposite method.

Syntax:

Get elements that do not meet the specified conditions:

$(selector).not(criteria)

Use a function to get elements:

$(selector).not(function(index))

Example

Return all paragraphs except the first one:

$("document").ready(function(){
  $("p").not(":first").css("background", "coral");
});
Test and see‹/›

Return all paragraphs without the class name "demo":

$("document").ready(function(){
  $("p").not(".demo").css("background", "coral");
});
Test and see‹/›

Return all items even if they are not:

$("document").ready(function(){
  $("li").not(":even").css("background", "coral");
});
Test and see‹/›

Change the background color of all divs; then add border color for those elements without the "middle" class name:

$("document").ready(function(){
  $("div").css("background", "#c8ebcc").not(".middle").css("border-color", "red");
});
Test and see‹/›

Use a function to filter out elements:

$("document").ready(function(){
  $("div").not(function(i){  
    return $(this).hasClass("middle");
  }).css("background-color", "blue");
});
Test and see‹/›

Parameter Value

ParameterDescription
criteriaSpecify a selector expression, a jQuery object, or one or more elements returned from a group of selected elements.
To specify multiple conditions, use commas
function(index)Specify a function to be used for testing each element in the collection
  • index - Return the index position of the element in the collection

jQuery Traversal Methods