Примеры для jQuery .not()


Adds a border to divs that are not green or blue.

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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>not demo</title>
<style>
div {
width: 50px;
height: 50px;
margin: 10px;
float: left;
background: yellow;
border: 2px solid white;
}
.green {
background: #8f8;
}
.gray {
background: #ccc;
}
#blueone {
background: #99f;
}
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div></div>
<div id="blueone"></div>
<div></div>
<div class="green"></div>
<div class="green"></div>
<div class="gray"></div>
<div></div>
<script>
$( "div" ).not( ".green, #blueone" )
.css( "border-color", "red" );
</script>
</body>
</html>

Демонстрация:

Removes the element with the ID "selected" from the set of all paragraphs.

1
$( "p" ).not( $( "#selected" )[ 0 ] );

Removes the element with the ID "selected" from the set of all paragraphs.

1
$( "p" ).not( "#selected" );

Removes all elements that match "div p.selected" from the total set of all paragraphs.

1
$( "p" ).not( $( "div p.selected" ) );