.not( selector )Returns: jQuery
Description: Remove elements from the set of matched elements.
-
version added: 1.0.not( selector )
-
selectorA string containing a selector expression, a DOM element, or an array of elements to match against the set.
-
-
version added: 1.4.not( function )
-
functionA function used as a test for each element in the set. It accepts two arguments,
index
, which is the element's index in the jQuery collection, andelement
, which is the DOM element. Within the function,this
refers to the current DOM element.
-
-
version added: 1.4.not( selection )
-
selectionType: jQueryAn existing jQuery object to match the current set of elements against.
-
.not()
method constructs a new jQuery object from a subset of the matching elements. The supplied selector is tested against each element; the elements that don't match the selector will be included in the result.
1
2
3
4
5
6
7
|
|
1
|
|
Removing Specific Elements
.not()
method allows us to remove elements from the matched set, assuming we have found those elements previously by some other means. For example, suppose our list had an id applied to one of its items:
1
2
3
4
5
6
7
|
|
getElementById()
function, then remove it from a jQuery object:
1
2
|
|
.not()
method can take a function as its argument in the same way that .filter()
does. Elements for which the function returns true
are excluded from the filtered set; all other elements are included.
.not()
, text and comment nodes will always be removed from the resulting jQuery object during the filtering process. When a specific node or array of nodes are provided, text or comment nodes will only be removed from the jQuery object if they match one of the nodes in the filtering array.
Examples:
Example 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
|
Demo:
Example 2
1
|
|
Example 3
1
|
|
Example 4
1
|
|