:not()S2C Home « Selectors « :not()

Negation pseudo-class selector.

Shorthand version $(':not(selector)')

Description

The :not() selector, selects all elements that do not match the given selector(s).

If this selector is not preceded by another selector, the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the example below to narrow the search and improve performance.

Syntax


Signature Description
jQuery(':not(selector)')Negation pseudo-class match

Parameters


Parameter Description
selectorValid selector(s) for filtering.

Return

N/A.

:not() Examplego to top of page Top

Selects all elements that do not match the given selector(s).

The following rather contrived example will check for input elements with an attribute of name that are not disabled (our input fields below) and set a message in them with a yellow background when the button below is clicked.


$(function(){
  $('#btn25').on('click', function() {
    $("input[name]:not(:disabled)").css('backgroundColor', 'yellow')
                                   .val("enter input"); 
  });
}); 

Please fill in the form:

Your Information

 Enter your name:


Press the button below to action the above code:


go to home page Homepage go to top of page Top