jQuery not() method
Example
Returndoes notall with class name "intro"
element:
$("p").not(".intro")
Try it »
Definition and Usage
The not() method returns elements that do not match a certain condition.
This method lets you specify a condition. Elements that do not match the condition are returned from the selection, and elements that match are removed.
This method is often used to remove one or more elements from a set of selected elements.
**Tip:** The not() method is the opposite of filter() method.
Syntax
$(
selector
).not(
criteria,
function
(index)
)
| Parameters | Description |
|---|---|
| criteria | Optional. Specifies a selector expression, jQuery object, or one or more elements to remove from the set of selected elements. |
**提示:**如需规定多个条件,请使用逗号分隔。 |
| function(index) | Optional. Specifies a function to run for each element in the set. If it returns true, the element is removed; otherwise the element is kept.
- index - the index position of the element in the set.
More examples
Return all that are not even-numbered
Element
Use the :even selector and not() to return all that are not even-numbered
.
Multiple conditions
How to return all whose class is not "intro" and id is not "outro"
.
Using a jQuery object
How to return via a jQuery object
.
DOM
How to return all whose id is not "intro" via a DOM element
.
Using the function
How to use a function to select those without two all having two elements inside them
.
jQuery Traversal Methods