ドキュメント

Selectors/multiple

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

selector1, selector2, selectorN

Matches the combined results of all the specified selectors.
You can specify any number of selectors to combine into a single result. Note order of the dom elements in the jQuery object aren't necessarily identical.
Arguments:

selector1Selector
Any valid selector
selector2Selector
Another valid selector
selectorN (Optional)Selector
As many more valid selectors as you like
Examples:

Finds the elements that match any of these three selectors.

$("div,span,p.myClass").css("border","3px solid 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,span,p.myClass").css("border","3px solid red");
  });
  </script>
  <style>
  div,span,p {
    width: 130px;
    height: 60px;
    float:left;
    padding: 3px;
    margin: 2px;
    background-color: #EEEEEE;
    font-size:14px;
  }
  </style>
</head>
<body>
  <div>div</div>
  <p class="myClass">p class="myClass"</p>
  <p class="notMyClass">p class="notMyClass"</p>
  <span>span</span>
</body>
</html>

$(":text").blur(function() {

 if(!this.value) {
  alert("Please enter some text!");
 }

});

Show the order in the jQuery object.

    var list = $("div,p,span").map(function () {
      return this.tagName;
    }).get().join(", ");
    $("b").append(document.createTextNode(list));

<!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(){
    
    var list = $("div,p,span").map(function () {
      return this.tagName;
    }).get().join(", ");
    $("b").append(document.createTextNode(list));

  });
  </script>
  <style>
  b { color:red; font-size:16px; display:block; clear:left; }
  div,span,p { width: 40px; height: 40px; float:left;
               margin: 10px; background-color: blue; 
               padding:3px; color:white; }
  </style>
</head>
<body>
  <span>span</span>
  <p>p</p>
  <p>p</p>
  <div>div</div>
  <span>span</span>
  <p>p</p>
  <div>div</div>
  <b></b>
</body>
</html>

NameType