ドキュメント

Selectors/all

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Selectors

*

Matches all elements.
Most useful when combined with a context to search in.
Examples:

Finds every element (including head, body, etc).

$("*").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(){
    $("*").css("border","3px solid red");
  });
  </script>
  <style>
  div,span,p {
    width: 150px;
    height: 60px;
    float:left;
    padding: 10px;
    margin: 10px;
    background-color: #EEEEEE;
  }
  </style>
</head>
<body>
  <div>DIV</div>
  <span>SPAN</span>
  <p>P <button>Button</button></p>
</body>
</html>

A common way to find all elements is to set the 'context' to document.body so elements like head, script, etc are left out.

$("*", document.body).css("border","3px solid red");

NameType