Cover by David Flanagan

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Name

Document — an HTML or XML document

Inherits from

Node

Synopsis

A Document object is a Node that serves as the root of a document tree. The document Element property is the root Element of the document. A Document node may have other children (such as Comment and DocumentType nodes), but it has only one Element child that holds all the content of the document.

You most commonly obtain a Document object via the document property of a Window. Document objects are also available through the contentDocument property of IFrame elements or the ownerDocument property of any Node.

Most of the properties of a Document object provide access to elements of the document or to other important objects associated with the document. A number of Document methods do the same thing: provide a way to look up elements within the document tree. Many other Document methods are “factory methods” that create elements and related objects.

Documents, like the Elements they contain, are event targets. They implement the methods defined by EventTarget, and they also support quite a few event handler properties.

You can create new Document objects by using the createDocument() and createHTML Document() methods of the DOMImplementation:

document.implementation.createHTMLDocument("New Doc");

It is also possible to load an HTML or XML file from the network and parse it into a Document object. See the responseXML property of the XMLHttpRequest object.

The reference entry for HTMLDocument, which appeared in previous versions ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required