jQuery .not() removes elements from the set of matched elements.
Syntax and Description
.not() removes elements from the set of matched elements.
.not(selector)
selector: A string containing a selector expression to match elements against.not(elements)
elements: One or more DOM elements to remove from the matched set.not(function)
function: A function used as a test for each element in the set
Return value is the new jQuery object.
Remove element by id
The following code removes paragraph element by its id.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- www .ja v a2s . c o m-->
$("p").not("#blue").css("border-color", "red");
});
</script>
</head>
<body>
<body>
<p>java2s.com</p>
<p id="blue">java2s.com</p>
<p class="green">java2s.com</p>
<p class="gray">java2 s.com</p>
</body>
</html>
Remove element by its style class
The following code removes paragraph element by its class name.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!--from w w w . jav a 2 s .c o m-->
$("p").not(".green").css("border-color", "red");
});
</script>
<style>
p {
width:60px;
height:60px;
margin:10px;
float:left;
background:yellow;
border:2px solid white;
}
</style>
</head>
<body>
<body>
<p>java2s.com</p>
<p id="blue">java2s.com</p>
<p class="green">jav a2s.com</p>
<p class="gray">java2s.com</p>
</body>
</html>