tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

:not(selector)

not selector

Description: Selects all elements that do not match the given selector.

jQuery(':not(selector)')

version added: 1.0
selector
A selector with which to filter by.

Examples

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.
    $("input:not(:checked) + span")
             .css("background-color", "yellow");
    $("input").attr("disabled", "disabled");
The output of the code above will be:

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

Additional Notes

The .not() method is typically faster and may end up providing you with more readable selections than pushing complex selectors or variables into a :not() selector filter.

Full source:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
  $(document).ready(function(){
    $("input:not(:checked) + span")
             .css("background-color", "yellow");
    $("input").attr("disabled", "disabled");
  });
  </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>
</body>
</html>
Was this information helpful?
   

Comments