.context in JQuery


Description: The DOM node context originally passed to jQuery(); if none was passed then context will likely be the document.

  • version added: 1.3context

The .live() method for binding event handlers uses this property to determine the root element to use for its event delegation needs. Plug-ins which perform similar tasks may also find the property useful.

The value of this property is typically equal to document, as this is the default context for jQuery objects if none is supplied. The context may differ if, for example, the object was created by searching within an <iframe> or XML document.


Determine the exact context used.

<!DOCTYPE html>
  body { cursor:pointer; }
  div { width:50px; height:30px; margin:5px; float:left;
        background:green; }
  span { color:red; }
  <script src="/scripts/jquery-1.4.js"></script>
  .append("<li>" + $("ul").context + "</li>")
  .append("<li>" + $("ul", document.body).context.nodeName + "</li>");


Leave a Reply

Your email address will not be published. Required fields are marked *