DekGenius.com
Team LiB   Previous Section   Next Section
Document an HTML or XML document

Availability

DOM Level 1 Core

Inherits from/Overrides

Node figs/U2192.gif Document

Subinterfaces

HTMLDocument

Also Implements

DocumentCSS

If the implementation supports the CSS module, the object that implements this Document interface also implements the DocumentCSS interface and its getOverrideStyle( ) method.

DocumentEvent

If the implementation supports the Events module, the object that implements this Document interface also implements the DocumentEvent interface and its createEvent( ) method.

DocumentRange

If the implementation supports the Range module, the object that implements this Document interface also implements the DocumentRange interface and its createRange( ) method.

DocumentStyle

If the implementation supports the StyleSheets module, the object that implements this Document interface also implements the DocumentStyle interface and its styleSheets property.

DocumentTraversal

If the implementation supports the Traversal module, the object that implements this Document interface also implements the DocumentTraversal interface and its createNodeIterator( ) and createTreeWalker( ) methods.

DocumentView

If the implementation supports the Views module, the object that implements this Document interface also implements the DocumentView interface and its defaultView property.

Because these interfaces define commonly implemented additions to the Document interface, their properties and methods are listed and documented here, as if they were directly part of the Document interface.

Properties

readonly AbstractView defaultView [DOM Level 2 Views]

The default view of this document. In a web-browser environment, this property specifies the Window object (which implements the AbstractView interface) in which the document is displayed.

Note that this property is technically part of the DocumentView interface; it is defined by the Document object only in implementations that support the Views module.

readonly DocumentType doctype

For XML documents with a <!DOCTYPE> declaration, specifies a DocumentType node that represents the document's DTD. For HTML documents and for XML documents with no <!DOCTYPE>, this property is null. Note that the property is read-only, and the node to which it refers is also read-only.

readonly Element documentElement

A reference to the root element of the document. For HTML documents, this property is always the Element object representing the <html> tag. This root element is also available through the childNodes[] array inherited from Node.

readonly DOMImplementation implementation

The DOMImplementation object that represents the implementation that created this document.

readonly StyleSheetList styleSheets [DOM Level 2 StyleSheets]

A collection of objects representing all style sheets embedded in or linked into a document. In HTML documents, this includes style sheets defined with <link> and <style> tags.

Note that this property is technically part of the DocumentStyle interface; it is defined by the Document object only in implementations that support the StyleSheets module.

Methods

createAttribute( )

Creates a new Attr node with the specified name.

createAttributeNS( ) [DOM Level 2]

Creates a new Attr node with the specified name and namespace.

createCDATASection( )

Creates a new CDATASection node containing the specified text.

createComment( )

Creates a new Comment node containing the specified string.

createDocumentFragment( )

Creates a new, empty DocumentFragment node.

createElement( )

Creates a new Element node with the specified tag name.

createElementNS( ) [DOM Level 2]

Creates a new Element node with the specified tag name and namespace.

createEntityReference( )

Creates a new EntityReference node that refers to an entity with the specified name. If the DocumentType object for this document defines an Entity with that name, the newly created EntityReference node is given the same read-only children that the Entity node has.

createEvent( ) [DOM Level 2 Events]

Creates a new synthetic Event object of the named type. Technically, this method is defined by the DocumentEvent interface; it is implemented by the Document object only in implementations that support the Events module.

createNodeIterator( ) [DOM Level 2 Traversal]

Creates a NodeIterator object. This method is technically part of the DocumentTraversal interface; it is implemented by the Document object only in implementations that support the Traversal module.

createProcessingInstruction( )

Creates a new ProcessingInstruction node with the specified target and data string.

createRange( ) [DOM Level 2 Range]

Creates a new Range object. This method is technically part of the DocumentRange interface; it is implemented by the Document object only in implementations that support the Range module.

createTextNode( )

Creates a new Text node to represent the specified text.

createTreeWalker( ) [DOM Level 2 Traversal]

Creates a TreeWalker object. This method is technically part of the DocumentTraversal interface; it is implemented by the Document object only in implementations that support the Traversal module.

getElementById( ) [DOM Level 2]

Returns a descendant Element of this document that has the specified value for its id attribute, or null if no such Element exists in the document.

getElementsByTagName( )

Returns an array (technically a NodeList) of all Element nodes in this document that have the specified tag name. The Element nodes appear in the returned array in the order in which they appear in the document source.

getElementsByTagNameNS( ) [DOM Level 2]

Returns an array of all Element nodes that have the specified tag name and namespace.

getOverrideStyle( ) [DOM Level 2 CSS]

Gets the CSS override style information for the specified Element (and an optional named pseudoelement). This method is technically part of the DocumentCSS interface; it is implemented by the Document object only in implementations that support the CSS module.

importNode( ) [DOM Level 2]

Makes a copy of a node from some other document that is suitable for insertion into this document.

Description

The Document interface is the root node of a document tree. A Document node may have multiple children, but only one of those children may be an Element node: it is the root element of the document. The root element is most easily accessed through the documentElement property. The doctype and implementation properties provide access to the DocumentType object (if any) and the DOMImplementation object for this document.

Most of the methods defined by the Document interface are "factory methods" that are used to create various types of nodes that can be inserted into this document. The notable exceptions are getElementById( ) and getElementsByTagName( ), which are quite useful for finding a specific Element or a set of related Element nodes within the document tree.

Contrast this Document object to the Document object documented in the client-side reference section of this book. The Level 0 properties and methods of that client-side Document object are formally defined by the DOM standard in the HTMLDocument interface. See HTMLDocument in this reference section for the DOM equivalent of the traditional client-side JavaScript Document object.

The Document interface is defined by the Core module of the DOM Level 2 specification. A number of the other modules define "add-on" interfaces that are intended to be implemented by the same object that implements the Document interface. For example, if an implementation supports the CSS module, the object that implements this interface also implements the DocumentCSS interface. In JavaScript, the properties and methods of these add-on interfaces can be used as if they were defined by Document, and for that reason, those methods and properties are listed here. See the earlier Section section for a full list of the add-on interfaces for Document.

See Also

HTMLDocument

Type of

AbstractView.document, HTMLFrameElement.contentDocument, HTMLIFrameElement.contentDocument, HTMLObjectElement.contentDocument, Node.ownerDocument

Returned by

DOMImplementation.createDocument( )

    Team LiB   Previous Section   Next Section