Not (:not(E))

Description and Syntax

$(':not(E)')

selects all elements that do not match the selector expression E.

Examples

SelectorSelects
$(':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(){<!--from   w  ww  . j  ava 2 s . c o 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>

Click to view the demo

The code above generates the following result.

Not (:not(E))