Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright 2012 Google Inc.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
    * use this file except in compliance with the License. You may obtain a copy of
    * the License at
    * 
    * http://www.apache.org/licenses/LICENSE-2.0
    * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   * License for the specific language governing permissions and limitations under
   * the License.
   */
  package elemental.dom;
  
  import elemental.util.*;
  import  elemental.dom.*;
  import elemental.html.*;
  import elemental.css.*;
  import elemental.svg.*;
  
  import java.util.Date;

Each web page loaded in the browser has its own document object. This object serves as an entry point to the web page's content (the DOM tree, including elements such as <body> and <table> ) and provides functionality global to the document (such as obtaining the page's URL and creating new elements in the document).

A document object can be obtained from various APIs:

  • Most commonly, you work with the document the script is running in by using document in document's scripts. (The same document can also be referred to as window.document.)
  • The document of an iframe via the iframe's contentDocument property.
  • The responseXML of an XMLHttpRequest object.
  • The document, that given node or element belongs to, can be retrieved using the node's ownerDocument property.
  • ...and more.

Depending on the kind of the document (e.g. HTML or XML) different APIs may be available on the document object. This theoretical availability of APIs is usually described in terms of implementing interfaces defined in the relevant W3C DOM specifications:

  • All document objects implement the DOM Core Document and Node interfaces, meaning that the "core" properties and methods are available for all kinds of documents.
  • In addition to the generalized DOM Core document interface, HTML documents also implement the HTMLDocument interface, which is a more specialized interface for dealing with HTML documents (e.g., document.cookie, document.alinkColor).
  • XUL documents (available to Mozilla add-on and application developers) implement their own additions to the core Document functionality.

Methods or properties listed here that are part of a more specialized interface have an asterisk (*) next to them and have additional information in theĀ  Availability column.

Note that some APIs listed below are not available in all browsers for various reasons:

  • Obsolete: on its way of being removed from supporting browsers.
  • Non-standard: either an experimental feature not (yet?) agreed upon by all vendors, or a feature targeted specifically at the code running in a specific browser (e.g. Mozilla has a few DOM APIs created for its add-ons and application development).
  • Part of a completed or an emerging standard, but not (yet?) implemented in all browsers or implemented in the newest versions of the browsers.

Detailed browser compatibility tables are located at the pages describing each property or method.

  
  public interface Document extends NodeNodeSelector {

Contains the set of standard values used with Document.createEvent(java.lang.String).
  
  public interface Events {
    public static final String CUSTOM = "CustomEvent";
    public static final String KEYBOARD = "KeyboardEvent";
    public static final String MESSAGE = "MessageEvent";
    public static final String MOUSE = "MouseEvent";
    public static final String MUTATION = "MutationEvent";
    public static final String OVERFLOW = "OverflowEvent";
    public static final String PAGE_TRANSITION = "PageTransitionEvent";
    public static final String PROGRESS = "ProgressEvent";
    public static final String STORAGE = "StorageEvent";
    public static final String TEXT = "TextEvent";
    public static final String UI = "UIEvent";
    public static final String WEBKIT_ANIMATION = "WebKitAnimationEvent";
    public static final String WEBKIT_TRANSITION = "WebKitTransitionEvent";
    public static final String WHEEL = "WheelEvent";
    public static final String SVGS = "SVGEvents";
    public static final String SVG_ZOOMS = "SVGZoomEvents";
    public static final String TOUCH = "TouchEvent";
  }

Contains the set of standard values returned by readyState.
  
  public interface ReadyState {

  
Indicates the document is still loading and parsing.
  
    public static final String LOADING = "loading";

  
Indicates the document is finished parsing but is still loading subresources.
 
   public static final String INTERACTIVE = "interactive";

  
Indicates the document and all subresources have been loaded.
 
   public static final String COMPLETE = "complete";
 }


  
Returns a string containing the URL of the current document.
 
   String getURL();


  
Returns the currently focused element
 
Returns or sets the color of active links in the document body.
 
 
   void setAlinkColor(String arg);
 
 
   void setAll(HTMLAllCollection arg);


  
Returns a list of all of the anchors in the document.
 
Returns an ordered list of the applets within a document.
 
Gets/sets the background color of the current document.
 
 
   void setBgColor(String arg);


  
Returns the BODY node of the current document.
 
 
   void setBody(Element arg);


  
Returns the character set being used by the document.
 
 
 
   void setCharset(String arg);


  
Indicates whether the document is rendered in Quirks or Strict mode.
 
   String getCompatMode();


  
Returns a semicolon-separated list of the cookies for that document or sets a single cookie.
 
 
   void setCookie(String arg);
 
Returns a reference to the window object.
 
Gets/sets WYSYWIG editing capability of Midas. It can only be used for HTML documents.
 
 
   void setDesignMode(String arg);


  
Gets/sets directionality (rtl/ltr) of the document
 
   String getDir();
 
   void setDir(String arg);


  
Returns the Document Type Definition (DTD) of the current document.
 
Returns the Element that is a direct child of document. For HTML documents, this is normally the HTML element.
 
Returns the document location.
 
 
   void setDocumentURI(String arg);


  
Returns the domain of the current document.
 
 
   void setDomain(String arg);


  
Returns a list of the embedded OBJECTS within the current document.
 
Gets/sets the foreground color, or text color, of the current document.
 
 
   void setFgColor(String arg);


  
Returns a list of the FORM elements within the current document.
 
Returns the HEAD node of the current document.
 
   HeadElement getHead();


  
Gets/sets the height of the current document.
 
   int getHeight();


  
Returns a list of the images in the current document.
 
Returns the DOM implementation associated with the current document.
 
Returns the encoding used when the document was parsed.
 
Returns the date on which the document was last modified.
 
Gets/sets the color of hyperlinks in the document.
 
 
   void setLinkColor(String arg);


  
Returns a list of all the hyperlinks in the document.
 
Returns the URI of the current document.
 
 
   void setLocation(Location arg);
 
 
   void setOnabort(EventListener arg);
 
 
 
 
   void setOnbeforecut(EventListener arg);
 
 
 
 
   void setOnblur(EventListener arg);
 
 
   void setOnchange(EventListener arg);
 
 
   void setOnclick(EventListener arg);
 
 
 
 
   void setOncopy(EventListener arg);
 
 
   void setOncut(EventListener arg);
 
 
   void setOndblclick(EventListener arg);
 
 
   void setOndrag(EventListener arg);
 
 
   void setOndragend(EventListener arg);
 
 
   void setOndragenter(EventListener arg);
 
 
   void setOndragleave(EventListener arg);
 
 
   void setOndragover(EventListener arg);
 
 
   void setOndragstart(EventListener arg);
 
 
   void setOndrop(EventListener arg);
 
 
   void setOnerror(EventListener arg);
 
 
   void setOnfocus(EventListener arg);
 
 
   void setOninput(EventListener arg);
 
 
   void setOninvalid(EventListener arg);
 
 
   void setOnkeydown(EventListener arg);
 
 
   void setOnkeypress(EventListener arg);
 
 
   void setOnkeyup(EventListener arg);
 
 
   void setOnload(EventListener arg);
 
 
   void setOnmousedown(EventListener arg);
 
 
   void setOnmousemove(EventListener arg);
 
 
   void setOnmouseout(EventListener arg);
 
 
   void setOnmouseover(EventListener arg);
 
 
   void setOnmouseup(EventListener arg);
 
 
 
 
   void setOnpaste(EventListener arg);


  
Returns the event handling code for the readystatechange event.

Gecko 9.0 note
(Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)

Starting in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6) , you can now use the syntax if ("onabort" in document) to determine whether or not a given event handler property exists. This is because event handler interfaces have been updated to be proper web IDL interfaces. See DOM event handlers for details.

 
 
 
 
   void setOnreset(EventListener arg);
 
 
   void setOnscroll(EventListener arg);
 
 
   void setOnsearch(EventListener arg);
 
 
   void setOnselect(EventListener arg);
 
 
 
 
 
 
   void setOnsubmit(EventListener arg);
 
 
 
 
   void setOntouchend(EventListener arg);
 
 
   void setOntouchmove(EventListener arg);
 
 
 
 
 
 
Returns a list of the available plugins.
 
 
Returns loading status of the document
 
   String getReadyState();


  
Returns the URI of the page that linked to this page.
 
   String getReferrer();


  
Returns all the <script> elements on the document.
 
 
 
   void setSelectedStylesheetSet(String arg);


  
Returns a list of the stylesheet objects on the current document.
 
Returns the title of the current document.
 
 
   void setTitle(String arg);


  
Gets/sets the color of visited hyperlinks.
 
 
   void setVlinkColor(String arg);
 
 
 
 
 
   boolean isWebkitHidden();
 
   boolean isWebkitIsFullScreen();
 
Returns the width of the current document.
 
   int getWidth();


  
Returns the encoding as determined by the XML declaration.
Firefox 10 and later don't implement it anymore.
 
Returns true if the XML declaration specifies the document is standalone (e.g., An external part of the DTD affects the document's content), else false.
 
   boolean isXmlStandalone();
 
   void setXmlStandalone(boolean arg);


  
Returns the version number as specified in the XML declaration or "1.0" if the declaration is absent.
 
 
   void setXmlVersion(String arg);


  
Adopt node from an external document
Node.appendChild
Adds a node to the end of the list of children of a specified parent node.
 
   Node adoptNode(Node source);
 
   Range caretRangeFromPoint(int xint y);


  
Creates a new attribute node and returns it.
 
   Attr createAttribute(String name);


  
Creates a new attribute node in a given namespace and returns it.
 
   Attr createAttributeNS(String namespaceURIString qualifiedName);


  
Creates a new CDATA node and returns it.
 
Creates a new comment node and returns it.
 
   Comment createComment(String data);


  
Creates a new document fragment.
 
Creates a new element with the given tag name.
 
   Element createElement(String tagName);


  
Creates a new element with the given tag name and namespace URI.
 
   Element createElementNS(String namespaceURIString qualifiedName);


  
Creates a new entity reference object and returns it.
 
Creates an event.
 
   Event createEvent(String eventType);


  
Compiles an XPathExpression which can then be used for (repeated) evaluations.
 
   XPathExpression createExpression(String expressionXPathNSResolver resolver);


  
Creates an XPathNSResolver.
 
 
   NodeIterator createNodeIterator(Node rootint whatToShowNodeFilter filterboolean expandEntityReferences);


  
Creates a new processing instruction element and returns it.
 
Creates a Range object.
 
   Range createRange();


  
Creates a text node.
 
 
   Touch createTouch(Window windowEventTarget targetint identifierint pageXint pageYint screenXint screenYint webkitRadiusXint webkitRadiusYfloat webkitRotationAnglefloat webkitForce);
 
Creates a treeWalker object.
 
   TreeWalker createTreeWalker(Node rootint whatToShowNodeFilter filterboolean expandEntityReferences);


  
Returns the element visible at the specified coordinates.
 
   Element elementFromPoint(int xint y);


  
Evaluates an XPath expression.
 
   XPathResult evaluate(String expressionNode contextNodeXPathNSResolver resolverint typeXPathResult inResult);


  
Executes a Midas command.
 
   boolean execCommand(String commandboolean userInterfaceString value);
 
   CanvasRenderingContext getCSSCanvasContext(String contextIdString nameint widthint height);


  
Returns an object reference to the identified element.
 
   Element getElementById(String elementId);


  
Returns a list of elements with the given class name.
 
Returns a list of elements with the given name.
 
   NodeList getElementsByName(String elementName);


  
Returns a list of elements with the given tag name.
 
Returns a list of elements with the given tag name and namespace.
Node.getFeature
 
   NodeList getElementsByTagNameNS(String namespaceURIString localName);
 
   CSSStyleDeclaration getOverrideStyle(Element elementString pseudoElement);


  
Returns a Selection object related to text selected in the document.
Node.getUserData
Returns any data previously set on the node via setUserData() by key
Node.hasAttributes
Indicates whether the node possesses attributes
Node.hasChildNodes
Returns a Boolean value indicating whether the current element has child nodes or not.
 
Returns a clone of a node from an external document
Node.insertBefore
Inserts the specified node before a reference node as a child of the current node.
Node.isDefaultNamespace
Returns true if the namespace is the default namespace on the given node
Node.isEqualNode
Indicates whether the node is equal to the given node
Node.isSameNode
Indicates whether the node is the same as the given node
Node.isSupported
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node or document
 
   Node importNode(Node importedNode);


  
Returns a clone of a node from an external document
Node.insertBefore
Inserts the specified node before a reference node as a child of the current node.
Node.isDefaultNamespace
Returns true if the namespace is the default namespace on the given node
Node.isEqualNode
Indicates whether the node is equal to the given node
Node.isSameNode
Indicates whether the node is the same as the given node
Node.isSupported
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node or document
 
   Node importNode(Node importedNodeboolean deep);


  
Returns true if the Midas command can be executed on the current range.
 
   boolean queryCommandEnabled(String command);


  
Returns true if the Midas command is in a indeterminate state on the current range.
 
   boolean queryCommandIndeterm(String command);


  
Returns true if the Midas command has been executed on the current range.
 
   boolean queryCommandState(String command);
 
   boolean queryCommandSupported(String command);


  
Returns the current value of the current range for Midas command. As of Firefox 2.0.0.2, queryCommandValue will return an empty string when a command value has not been explicitly set.
 
   String queryCommandValue(String command);


  
Returns the first Element node within the document, in document order, that matches the specified selectors.
 
   Element querySelector(String selectors);


  
Returns a list of all the Element nodes within the document that match the specified selectors.
 
   NodeList querySelectorAll(String selectors);
 
 
 
   void captureEvents();


  
In majority of modern browsers, including recent versions of Firefox and Internet Explorer, this method does nothing.
Node.cloneNode
Makes a copy of a node or document
 
   void clear();


  
Closes a document stream for writing.
Node.compareDocumentPosition
Compares the position of the current node against another node in any other document.
 
   void close();


  
Returns true if the focus is currently located anywhere inside the specified document.
 
   boolean hasFocus();


  
Opens a document stream for writing.
 
   void open();


  
Node.removeChild
Removes a child node from the DOM
 
   void releaseEvents();


  
Writes text to a document.
 
   void write(String text);


  
Write a line of text to a document.
 
   void writeln(String text);