:not() Selector in JQuery

 

Sample:

version added: 1.0jQuery(‘:not(selector)’)

  • selector
    A selector with which to filter by.

All selectors are accepted inside :not(), for example: :not(div a) and :not(div,a).

Example:

Finds all inputs that are not checked and highlights the next sibling span. Notice there is no change when clicking the checkboxes since no click events have been linked.

<!DOCTYPE html>
<html>
<head>
  <script src="/scripts/jquery-1.4.js"></script>
</head>
<body>
	<div>
  <input type="checkbox" name="a" />
  <span>Mary</span>
</div>

<div>
  <input type="checkbox" name="b" />
  <span>lcm</span>

</div>
<div>
  <input type="checkbox" name="c" checked="checked" />

  <span>Peter</span>
</div>
<script>
  $("input:not(:checked) + span").css("background-color", "yellow");
  $("input").attr("disabled", "disabled");

</script>
</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *