jQuery: The Write Less, Do More JavaScript Library

Selectors/not

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

:not(selector)

Filters out all elements matching the given selector.
Arguments:
selectorSelector
A selector with which to filter by.

Examples:
Finds all inputs that are not checked and hilites 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");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="../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>Paul</span>
  </div>
  <div>
    <input type="checkbox" name="c" checked="checked" />
    <span>Peter</span>
  </div>
</body>
</html>

NameType