ドキュメント

Traversing/not

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Traversing

not( expr )

Removes elements matching the specified expression from the set of matched elements.
Arguments:
exprString, DOMElement, Array<DOMElement>
An expression with which to remove matching elements, an element to remove from the set or a set of elements to remove from the jQuery set of matched elements. A jQuery object is also accepted.
Examples:

Adds a border to divs that are not green or blue.

    $("div").not(".green, #blueone")
            .css("border-color", "red");

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>
  $(document).ready(function(){
    
    $("div").not(".green, #blueone")
            .css("border-color", "red");

  });
  </script>
  <style>
  div { width:60px; height:60px; margin:10px; float:left;
        background:yellow; border:2px solid white; }
  .green { background:#8f8; }
  .gray { background:#ccc; }
  #blueone { background:#99f; }
  </style>
</head>
<body>
  <div></div>
  <div id="blueone"></div>
  <div></div>
  <div class="green"></div>
  <div class="green"></div>
  <div class="gray"></div>
  <div></div>
</body>
</html>

Removes the element with the ID "selected" from the set of all paragraphs.

$("p").not( $("#selected")[0] )

Removes the element with the ID "selected" from the set of all paragraphs.

$("p").not("#selected")

Removes all elements that match "div p.selected" from the total set of all paragraphs.

$("p").not($("div p.selected"))

NameType