jQuery not(negate) selector
Description and Syntax
$(':not(E)')
selects all elements that do not match the selector expression E.
Examples
Selector | Selects |
---|---|
$(':not(.myclass)') | all elements in the document that do not have the class myclass |
$('li:not(:last-child)') | all <li> elements that are not the last child of their parent elements |
The following code selects the not selected elements.
<html>
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){<!-- w ww. j a v a 2 s. co m-->
$("input:not(:checked) + span").css("background-color", "yellow");
});
</script>
</head>
<body>
<body>
<div>
<input type="checkbox" name="a" />
<span>A</span>
</div>
<div>
<input type="checkbox" name="b" />
<span>B</span>
</div>
<div>
<input type="checkbox" name="c" checked="checked" />
<span>C</span>
</div>
</body>
</html>