jQuery not()Method

jQuery 遍历方法jQuery Traversing Methods

Example

ReturnNoAll <p> elements with class name "intro":

$("p").not(".intro")

Try it Yourself »

Definition and Usage

The not() method returns elements that do not meet a certain condition.

This method lets you specify a condition. Elements that do not meet the condition will be returned from the selection, while elements that meet the condition will be removed.

This method is usually used to remove one or more elements from a group of selected elements.

Tip:The not() method is the opposite of thefilter()method.


Syntax

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

Parameter Description
criteria Optional. Specifies a selector expression, a jQuery object, or one or more elements to be removed from the group of selected elements.

Tip:To specify multiple conditions, separate them with commas.
function(index) Optional. Specifies a function to run for each element in the group. If it returns true, the element is removed; otherwise, the element will be kept.
  • index- The index position of the element in the set.
Note: thisis the current DOM element.

实例

More Examples

Return all <p> elements that are not even-numbered
Use the :even selector and not() to return all <p> elements that are not even-numbered.

Multiple conditions
How to return all <p> elements whose class is not "intro" and whose id is not "outro".

Using a jQuery object
How to use a jQuery object to return all <p> elements inside a <div> element whose class is not "intro".

DOM
How to use a DOM element to return all <p> elements whose id is not "intro".

Using a function
How to use a function to select all <p> elements that do not have two <span> elements inside them.


jQuery 遍历方法jQuery Traversing Methods

Other extensions