ドキュメント

Core/context

From jQuery JavaScript Library

Jump to: navigation, search

« Back to Core

context

New in jQuery 1.3 The DOM node context originally passed to jQuery() (if none was passed then context will be equal to the document).

Should be used in conjunction with selector to determine the exact query used. These two properties are mostly useful to plugin developers.

Examples:

Determine the exact context used.

$("ul")
  .append("<li>" + $("ul").context + "</li>")
  .append("<li>" + $("ul", document.body).context.nodeName + "</li>");

<!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(){
    $("ul")
  .append("<li>" + $("ul").context + "</li>")
  .append("<li>" + $("ul", document.body).context.nodeName + "</li>");

  });
  </script>
  <style>
  body { cursor:pointer; }
  div { width:50px; height:30px; margin:5px; float:left;
        background:green; }
  span { color:red; }
  </style>
</head>
<body>
  Context:<ul></ul>
</body>
</html>

NameType