Document : Node

Represents an HTML or XML document.

Browser/User Agent Support

IEMozillaNetscapeOperaSafariNetscapte
3.0+1.0+2.0+7.0+1.0+no

Constructors

ConstructorIEMozillaNetscapeOperaSafariNetscapte
Creates a new instance of a Document object.
3.0+1.0+2.0+7.0+1.0+no
 

Properties

PropertyIEMozillaNetscapeOperaSafariNetscapte
Reference to the Element that currently has focus.
4.0+nonononono
 
Specifies the color of active links.
3.0+1.0+2.0+7.0+1.0+no
 
Array of all of the Anchor objects in a document.
3.0+1.0+2.0+7.0+1.0+no
 
Array of all of the Applet objects in a document.
4.0+1.0+3.0+7.0+1.0+no
 
Background color of a document.
3.0+1.0+2.0+7.0+1.0+no
 
Reference to the body or frameset element.
4.0+1.0+6.0+7.0+1.0+no
 
Character set of the document.
4.0+nonononono
 
Character set of the document.
no1.0+6.0+no1.0+no
 
Array of style properties for CSS classes.
nono4.0+nonono
 
Indicates whether the document has standards-compliant mode turned on.
6.0+1.75+7.0+nonono
 
Value of the cookie that the browser has set for the document.
3.0+1.0+2.0+7.0+1.0+no
 
Default character set for the document.
4.0+nonononono
 
Specifies that design mode for an HTML document is "on" or "off."
5.0+1.4+7.0+nonono
 
Text direction of the content in the document.
5.0+1.0+6.0+nonono
 
Document Data Type (DTD) associated with this document.
6.0+1.0+6.0+7.0+nono
 
Root element in a document.
5.0+1.0+6.0+7.0+1.0+no
 
Internet domain of the document.
4.0+1.0+3.0+7.0+1.0+no
 
Array of all embedded objects in the document.
4.0+1.0+3.0+7.0+1.0+no
 
Indicates whether a client-side object may have instance properties added to it.
4.0+nonononono
 
Font color of the document text.
3.0+1.0+2.0+7.0+1.0+no
 
Date that the document was created.
4.0+nonononono
 
Date that the document was last modified.
4.0+nonononono
 
File size (in bytes) of the document.
4.0+nonononono
 
Array of all of the Forms in the document.
3.0+1.0+2.0+7.0+1.0+no
 
Array of all of the Frames in the document.
4.0+nonononono
 
Height of the entire HTML document (in pixels).
no1.0+4.0+7.0+1.0+no
 
Array of style properties in the document set by the Id attribute.
nono4.0+nonono
 
Array of Image objects in the document.
4.0+1.0+3.0+7.0+1.0+no
 
Object that specifies whether or not and at what level the browser supports the specified feature.
6.0+1.0+6.0+7.0+1.0+no
 
Date that the document was last modified.
3.0+1.0+2.0+7.0+1.0+no
 
Array of all of the Layer elements in the document.
nono4.0+nonono
 
Color of the unvisited links in the document.
3.0+1.0+2.0+7.0+1.0+no
 
Array of all of the links in the document.
3.0+1.0+2.0+7.0+1.0+no
 
Complete URL of the document.
3.0+no3-4nonono
 
The media that the document is intended for.
5.5+nonononono
 
Information about the document MIME type.
5.0+nonononono
 
Array of the XML Namespaces for a document.
5.5+nonononono
 
Fires when the element becomes active.
4.0+nonononono
 
Fires immediately before the selection is cut to the clipboard.
4.0+nonono1.0+no
 
Fires immediately before the element stops being the active element.
4.0+nonononono
 
Fires immediately before the element receives focus prior to being edited.
4.0+nonononono
 
Fires immediately before the selection is pasted from the clipboard to the element.
4.0+nonono1.0+no
 
Fires when the element is clicked.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when the element is right-clicked and the context menu opens.
4.0+nonono1.0+no
 
Fires immediately before the element is selected.
4.0+nonononono
 
Fires when the element is cut to the clipboard.
4.0+nonono1.0+no
 
Fires when the element is double-clicked.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when the element is dragged.
4.0+nonono1.0+no
 
Fires when the element is released from being dragged.
4.0+nonono1.0+no
 
Fires when the element has another object dragged onto it that can be dropped on the element.
4.0+nonono1.0+no
 
Fires when an element has an object dragged out of it that could be dropped onto the element.
4.0+nonono1.0+no
 
Fires when an element has an object dragged over it that could be dropped onto the element.
4.0+nonono1.0+no
 
Fires immediately before an element is dragged.
4.0+nonono1.0+no
 
Fires when an object is dropped onto the element.
4.0+nonono1.0+no
 
Fires when a user presses the F1 key to activate help.
4.0+nonononono
 
Fires when a user presses down on a key while the element has focus.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when a user presses a key or holds down the key while the element has focus.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when a user releases a key while the element has focus.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when a user clicks down on the mouse button while the element has focus.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when the mouse moves while the pointer over the element.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when the mouse pointer moves off of the element.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when the mouse pointer moves over the element.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when the user releases the mouse button while the element has focus.
2.0+1.0+1.0+4.0+1.0+no
 
Fires when the clipboard contents are pasted onto the element.
4.0+nonono1.0+no
 
Fires when one of the properties of the element changes.
4.0+nonononono
 
Fires when the ready state of the element changes.
4.0+nonononono
 
Fires immediately before an element is about to be resized.
4.0+nonono1.0+no
 
Fires when the element is finished being resized.
4.0+nonononono
 
Fires immediately before a user resizes the element.
4.0+nonononono
 
Fires when the selected state of the document changes.
5.5+nonononono
 
Fires when a user clicks the Stop button on the browser.
5.5+nonononono
 
Reference to the parent Window of the document.
4.0+nono8.0+nono
 
Array of plugins installed in the browser.
2.0+1.0+1.0+7.0+1.0+no
 
Full name of the protocol (not "http") used to retrieve the document.
4.0+nonononono
 
URL of the referring document.
2.0+1.0+1.0+7.0+1.0+no
 
Array of all of the Scripts in the document.
4.0+nonononono
 
Information about the security certificate for the document.
5.5+nonononono
 
Object representing any currently selected text.
4.0+nonononono
 
Array of all of the styleSheets in the document.
4.0+1.0+6.0+7.0+1.2+no
  • Safari: Cannot access disabled or alternate stylesheets.
Array of style properties for certain HTML tags.
nono4.0+nonono
 
Title of the document.
3.0+1.0+2.0+7.0+1.0+no
 
URL of the document.
4.0+1.0+2.0+nonono
 
URL-unencoded version of the URL.
5.5+nonononono
 
Color of visited links.
3.0+1.0+2.0+7.0+1.0+no
 
Width of the HTML document (in pixels).
no1.0+4.0+7.0+1.0+no
 
Reference to the top-level node of the XML DOM used by the document.
5.0+nonononono
 
Reference to the XSL document for the document.
5.0+nonononono
 

Methods

MethodIEMozillaNetscapeOperaSafariNetscapte
Sets an document to capture the events specified by eventMask.
nono4.0+nonono
 
Clears the content from the document.
3.0+1.0+2.0+no1.0+no
 
Stops the output stream to the document.
3.0+1.0+2.0+7.0+1.0+no
 
Sets a concept to select tags to style.
nono4.0nonono
 
Creates a new Attr node
6.0+1.0+6.0+7.0+1.0+no
  • Safari: Safari will create the attribute, but you will have to use nodeValue to set its value.
Creates a new Attr using a namespace.
6.0+1.0+6.0+7.0+1.0+no
 
Creates a new CDATASection node
no1.0+nononono
 
Creates a new Comment node
3.0+1.0+2.0+7.0+1.0+no
 
Creates an empty DocumentFragment object
6.0+1.0+2.0+7.0+1.0+no
 
Creates a new Element node of the type specified by tagName (e.g. li element.)
5.0+1.75+6.0+8.0+1.3+no
  • IE: IE also supports the syntax "createElement('<p>')".
Creates a new Element node with a namespace.
no1.0+6.0+9.0+1.3+no
 
Creates a new EntityReference object
no1.0+nononono
 
Creates a new Event object to be used by the fireEvent method.
5.0+nonononono
 
Creates a new ProcessingInstruction node with the specified target and data strings.
no1.0+nononono
 
Creates a new StyleSheet object.
4.0+nonononono
 
Creates a new Text node.
5.0+1.75+no8.0+1.3+no
 
Returns the element found at the specified x, y location in the document.
4.0+nonononono
 
Executes the specified command on the document.
4.0+1.4+7.1+nonono
 
Gives focus to the document and fires the onfocus event handler.
5.5+nonononono
 
Returns the Element node that matches the given ID.
5.0+1.0+6.0+7.0+1.0+no
  • IE: In addition to returning the element with the specified "id", IE will also return an element with a "name" that equals the specified "id".
Returns an array of Element nodes with the specified tag name.
5.0+1.0+6.0+7.0+1.0+no
  • IE: Does not work in IE 5.0 on Windows.
Returns the Element nodes with the specified element name and namespace.
no1.0+nononono
 
Returns the text currently selected by the user.
nono4.0+nonono
 
Imports a node from a different document.
no1.0+nononono
 
Returns true if the specified feature and version are supported.
no1.0+6.0+nonono
 
Opens the document for writing.
3.0+1.0+2.0+7.0+1.0+no
 
Returns true if the specified command is enabled.
4.0+1.4+7.1+nonono
 
Returns true if the specified command is in an indeterminate state.
4.0+1.4+7.1+nonono
 
Returns true if the specified command has been executed on the object.
4.0+1.4+7.1+nonono
 
Returns true if the specified command is supported.
4.0+1.4+7.1+nonono
 
Returns the value of the specified command for the document. Returns false if the command is not supported.
4.0+1.4+7.1+nonono
 
Reevaluates all dynamic properties in the document.
5.0+nonononono
 
Sets the document to stop capturing the specified type of events.
nono4.0+nonono
 
Routes the specified event to the next event handler.
nono4.0+nonono
 
Gives information about the currently selected objects in the document.
4.0+nonononono
 
Writes the specified string of text to the end of the document.
3.0+1.0+2.0+7.0+1.0+no
 
Writes the specified string of text to the end of the document and adds a newline character at the end of the text.
3.0+1.0+2.0+7.0+1.0+no
 

Remarks

This object interface represents an entire HTML or XML document. For most applications, this will be the effective root of an object tree, since elements, text nodes, and other XML-based source content cannot exist outside of a Document object. This object contains all the factory methods necessary to create additional objects along these lines. All nodes created with this document have their ownerDocument property set to this one.

Within Mozilla (either with XUL running in a chrome environment, or HTML working within a browser) the Document object representing the current document is usually set automatically to the global document variable. This global variable is often referenced in sample documentation, and can be used within your code as well.

References

HTMLDocument

Availability

HTML DOM Level 1 | HTML DOM Level 2 | W3C

Constructor Detail

Document Document()

Creates a new instance of a Document object.

Visibility
internal

Property Detail

Element activeElement - read only

Reference to the Element that currently has focus.

String alinkColor

Specifies the color of active links.

Remarks
Use the alink property of the tag to initially set the color of active links. To set this property, use the color properties of HTMLBodyElement to set the color in the tag.
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

Array anchors - read only

Array of all of the Anchor objects in a document.

Remarks
Because the Anchors array is read-only, modify the array by adding and deleting anchor elements. Do not confuse Anchors with hypertext links.
Availability

HTML DOM Level 1

Array applets - read only

Array of all of the Applet objects in a document.

Remarks
Because the Applets array is read-only, modify the array by adding and deleting applet elements.
Availability

HTML DOM Level 1

String bgColor

Background color of a document.

Remarks
Use the bgColor property of the tag to set the document background color. To set this bgColor, use the color properties of HTMLBodyElement to set the color at any time.
See Also

HTMLBodyElement

Availability

HTML DOM Level 1

Element body

Reference to the body or frameset element.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/document.html

Remarks

For additional compatibility information, see the quirksmode page:

http://www.quirksmode.org/viewport/compatibility.html

Availability

HTML DOM Level 1

String charset - read only

Character set of the document.

String characterSet - read only

Character set of the document.

Array classes - read only

Array of style properties for CSS classes.

Boolean compatMode

Indicates whether the document has standards-compliant mode turned on.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/compatmode_off.html

String cookie

Value of the cookie that the browser has set for the document.

Availability

HTML DOM Level 1

String defaultCharset - read only

Default character set for the document.

String designMode

Specifies that design mode for an HTML document is "on" or "off."

Remarks
If design mode is on, a user can double-click the document to edit its HTML.

String dir

Text direction of the content in the document.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/taginfo.html

Availability

HTML DOM Level 0

DocumentType doctype - read only

Document Data Type (DTD) associated with this document.

Remarks
Every document can contain a Document Type Declaration (DTD) that defines document structure and entity references for the document. The doctype property represents the state of this document's DTD, which is either a DocumentType object, or null, if no DTD is specified.
Availability

HTML DOM Level 2 | W3C

Element documentElement - read only

Root element in a document.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/document.html

Remarks

documentElement is a convenience property for accessing the contents of a document.

Without the

documentElement property, you would have to write doc.childNodes.item(0) or doc.childNodes[0] to access the contents of a document, instead of just typing doc.documentElement.

Availability

HTML DOM Level 2 | W3C

String domain

Internet domain of the document.

Availability

HTML DOM Level 1

Array embeds - read only

Array of all embedded objects in the document.

Remarks
embeds is a read-only property. You can add, delete, or modify the individual objects in the array, but you cannot modify the array itself.
See Also

Document.plugins

Boolean expando

Indicates whether a client-side object may have instance properties added to it.

Remarks
Use expando to help catch typos and case-sensitivity issues in your JavaScript.

String fgColor

Font color of the document text.

Remarks
Use the fgColor property of the <body> tag to initially set the color of the document text. To set this property, use the color properties of HTMLBodyElement to set the color in the <head> tag.
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

String fileCreatedDate - read only

Date that the document was created.

String fileModifiedDate - read only

Date that the document was last modified.

Number fileSize - read only

File size (in bytes) of the document.

Array forms - read only

Array of all of the Forms in the document.

Remarks
Although the Forms array is read-only, you can modify the individual Form elements.
Availability

HTML DOM Level 1

Array frames - read only

Array of all of the Frames in the document.

Remarks
Although the Frames array is read-only, you can modify the individual Frame elements.

Number height - read only

Height of the entire HTML document (in pixels).

Array ids - read only

Array of style properties in the document set by the Id attribute.

Remarks
Although the Ids array is read-only, you can modify the individual Id elements.

Array images - read only

Array of Image objects in the document.

Remarks
Although the Images array is read-only, you can modify the individual Image elements.
Availability

HTML DOM Level 1

Object implementation - read only

Object that specifies whether or not and at what level the browser supports the specified feature.

Availability

HTML DOM Level 2 | W3C

String lastModified - read only

Date that the document was last modified.

Availability

HTML DOM Level 0

Array layers - read only

Array of all of the Layer elements in the document.

Remarks
Includes divs positioned by CSS.

String linkColor

Color of the unvisited links in the document.

See Also

HTMLBodyElement

Availability

HTML DOM Level 0

Array links - read only

Array of all of the links in the document.

Remarks
Although the Link array is read-only, you can modify the individual Link elements.
Availability

HTML DOM Level 1

Object location

Complete URL of the document.

Remarks
Deprecated for Window.location.
See Also

Window.location

String media

The media that the document is intended for.

String mimeType - read only

Information about the document MIME type.

Array namespaces - read only

Array of the XML Namespaces for a document.

Function onactivate - read only

Fires when the element becomes active.

Function onbeforecut - read only

Fires immediately before the selection is cut to the clipboard.

Function onbeforedeactivate - read only

Fires immediately before the element stops being the active element.

Function onbeforeeditfocus - read only

Fires immediately before the element receives focus prior to being edited.

Function onbeforepaste - read only

Fires immediately before the selection is pasted from the clipboard to the element.

Function onclick - read only

Fires when the element is clicked.

Function oncontextmenu - read only

Fires when the element is right-clicked and the context menu opens.

Function oncontrolselect - read only

Fires immediately before the element is selected.

Function oncut - read only

Fires when the element is cut to the clipboard.

Function ondblclick - read only

Fires when the element is double-clicked.

Function ondrag - read only

Fires when the element is dragged.

Function ondragend - read only

Fires when the element is released from being dragged.

Function ondragenter - read only

Fires when the element has another object dragged onto it that can be dropped on the element.

Function ondragleave - read only

Fires when an element has an object dragged out of it that could be dropped onto the element.

Function ondragover - read only

Fires when an element has an object dragged over it that could be dropped onto the element.

Function ondragstart - read only

Fires immediately before an element is dragged.

Function ondrop - read only

Fires when an object is dropped onto the element.

Function onhelp - read only

Fires when a user presses the F1 key to activate help.

Function onkeydown - read only

Fires when a user presses down on a key while the element has focus.

Function onkeypress - read only

Fires when a user presses a key or holds down the key while the element has focus.

Function onkeyup - read only

Fires when a user releases a key while the element has focus.

Function onmousedown - read only

Fires when a user clicks down on the mouse button while the element has focus.

Function onmousemove - read only

Fires when the mouse moves while the pointer over the element.

Function onmouseout - read only

Fires when the mouse pointer moves off of the element.

Function onmouseover - read only

Fires when the mouse pointer moves over the element.

Function onmouseup - read only

Fires when the user releases the mouse button while the element has focus.

Function onpaste - read only

Fires when the clipboard contents are pasted onto the element.

Function onpropertychange - read only

Fires when one of the properties of the element changes.

Function onreadystatechange - read only

Fires when the ready state of the element changes.

Function onresize - read only

Fires immediately before an element is about to be resized.

Function onresizeend - read only

Fires when the element is finished being resized.

Function onresizestart - read only

Fires immediately before a user resizes the element.

Function onselectionchange - read only

Fires when the selected state of the document changes.

Function onstop - read only

Fires when a user clicks the Stop button on the browser.

Object parentWindow - read only

Reference to the parent Window of the document.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/window.html

See Also

Window

Array plugins - read only

Array of plugins installed in the browser.

Remarks
Synonym for the embeds[] array.
See Also

Document.embeds

String protocol

Full name of the protocol (not "http") used to retrieve the document.

Remarks
IE only. Supported in IE4+.

String referrer - read only

URL of the referring document.

Remarks
If a user reaches the current document by clicking a link in another document, the referrer property holds the URL for the document with the link. If the user typed the URL into the address bar, the referrer property is an empty string.
Availability

HTML DOM Level 1

Array scripts - read only

Array of all of the Scripts in the document.

String security - read only

Information about the security certificate for the document.

Object selection - read only

Object representing any currently selected text.

Array styleSheets - read only

Array of all of the styleSheets in the document.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/stylesheets.html

Availability

HTML DOM Level 2

Array tags - read only

Array of style properties for certain HTML tags.

String title - read only

Title of the document.

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/innerhtml.html

Remarks
The title is the text that appears between the title tags of an HTML document.
Availability

HTML DOM Level 1

String URL

URL of the document.

Remarks
See Also

location.href

String URLUnencoded - read only

URL-unencoded version of the URL.

See Also

Document.URL

String vlinkColor

Color of visited links.

Remarks
Use the vlink property of the tag to initially set the color of visted links. To set this property, use the color properties of HTMLBodyElement to set the color in the tag.
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

Number width - read only

Width of the HTML document (in pixels).

Object XMLDocument

Reference to the top-level node of the XML DOM used by the document.

Object XSLDocument - read only

Reference to the XSL document for the document.

Method Detail

captureEvents(Number eventMask) : void

Sets an document to capture the events specified by eventMask.

NumbereventMaskBitmask containing the events to capture.

Remarks
Supported in Mozilla and NS4+.
See Also

releaseEvents

clear() : void

Clears the content from the document.

close() : Object

Stops the output stream to the document.

Availability

HTML DOM Level 0

contextual(String context) : void

Sets a concept to select tags to style.

StringcontextName of the context to be used. (one-or-more)

createAttribute(String name) : static Attr

Creates a new Attr node

StringnameName of the attribute to create.

Using createAttribute

var ele = document.createElement('a');
                    var href = document.createAttribute('href');
                    href.value = 'http://mozref.com';
                    ele.setAttributeNode(href);
                    ele.appendChild(document.createTextNode('Mozilla AOM Reference'));

For more examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/attributes3.html

Remarks

Although Attribute objects can only be bound to Element objects, they can be created by a Document object and later be bound to an element using setAttributeNode.

While an Attr node may contain several different properties, this method only populates the nodeName property and sets the attribute value set to null. The localName, prefix, and namespaceURI properties are all set to null. To set those values, use the createAttributeNS method.

Throws
Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
See Also

Attr | Element.setAttribute | Element.setAttributeNode

Availability

HTML DOM Level 2 | W3C

createAttributeNS(String namespaceURI, String qualifiedName) : static Attr

Creates a new Attr using a namespace.

StringnamespaceURIThe namespace of the new attribute.
StringqualifiedNameThe qualified name (e.g. rdf:about) of the attribute to create.

Remarks

Similar to createAttribute, createAttributeNS creates a new Attr within the current document, but createAttributeNS uses namespaces and can populate many of the attribute properties using the specified namespaceURI, qualifiedName objects.

This method will do its best to populate as many propertys as it can, to the best of its ability. For more information about these properties, please see their respective objects.

Throws
Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
Raises NAMESPACE_ERR error if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/".
See Also

Attr

Availability

HTML DOM Level 2 | W3C

createCDATASection(Object data) : CDATASection

Creates a new CDATASection node

ObjectdataThe text to wrap up into a new CDATASection object.

Using createCDATASection

var cdata = document.createCDATASection(
                    'this &p invalid markup &exists in this CDATA & section'
                    );
                    var obj = document.getElementById('header');
                    obj.appendChild(cdata);
Remarks
Creates a new CDATASection object within the current document, representing a region of uninterpreted content. Any text within this object, with the exception of the string "]]>", will not be encoded or otherwise interpreted by the DOM engine.
Throws
Raises a NOT_SUPPORTED_ERR error if the current document is an HTML document.
Availability

HTML DOM Level 2 | W3C

createComment(String data) : Comment

Creates a new Comment node

StringdataThe text to include in the comment.

Using createComment

var comment = document.createComment('this text will not appear in HTML');
                    var obj = document.getElementById('header');
                    obj.appendChild(comment);
Remarks
Creates a new Comment object that can be used for adding a region of commented text for inclusion into the current document. Any text within this object, with the exception of the string "-->" will be protected within the document.
Availability

HTML DOM Level 2 | W3C

createDocumentFragment() : DocumentFragment

Creates an empty DocumentFragment object

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/docfrag.html

Availability

HTML DOM Level 2 | W3C

createElement(String tagName) : static HTMLElement

Creates a new Element node of the type specified by tagName (e.g. li element.)

StringtagNameThe tag name of the element to be created.

Using createElement

var newList = document.createElement('ol');
                    newList.setAttribute('class', 'features');
                    document.getElementById('sidebar').appendChild(newList);

For additional examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/basics.html

Remarks

Use createElement to create a new Element to later include in the Document. Returns a new Element, complete with any default attributes that are defined by the the DocumentType object, which represents the DTD for the document.

Because createElement does not support namespaces, the localName, prefix, and namespaceURI properties are all set to null. To create elements with namespaces (e.g. XUL elements), use createElementNS.

Throws
Raises an INVALID_CHARACTER_ERR error if the specified name contains an illegal character.
Availability

HTML DOM Level 2 | W3C

createElementNS(String namespaceURI, String qualifiedName) : static HTMLElement

Creates a new Element node with a namespace.

StringnamespaceURINamespace of the new element.
StringqualifiedNameQualified name (e.g. myns:element) of the element to create.

Using createElementNS

var newButton = document.createElement(
                    'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',
                    'xul:button'
                    );
Remarks

Use createElementNS to create a new element with a namespace in a document.

By simply supplying both the namespace URI and the qualified name of the element, the following values are extracted to create a fully-formed namespace-aware element:

Element properties set by <code>createElementNS</code>PropertyleftValueleftlocalName The local name of this tag name, extracted from qualifiedNamenamespaceURInamespaceURInodeNamequalifiedNameprefix The namespace prefix extracted from qualifiedName, or null if this element does not define a prefix tagNamequalifiedName
Throws
Raises an INVALID_CHARACTER_ERR error if the specified qualified name contains an illegal character.
Raises a NAMESPACE_ERR error if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace"
Availability

HTML DOM Level 2 | W3C

createEntityReference(String name) : static EntityReference

Creates a new EntityReference object

StringnameName of the new entity reference.

Remarks

Creates a new EntityReference object with the specified name.

If the requested entity name is already known to the current document, the returned EntityReference object's children are set to the same as the corresponding Entity. This makes creating entity references in your document much easier, since it eliminates a step.

Throws
Raises an INVALID_CHARACTER_ERR error if the specified name contains illegal characers. Raises a NOT_SUPPORTED_ERR error if the current document is an HTML document.
Availability

HTML DOM Level 2 | W3C

createEventObject(String eventObj) : static Event

Creates a new Event object to be used by the fireEvent method.

StringeventObjEvent to clone properties for, if copying from an existing Event. (zero-or-more)

See Also

Event | MouseEvent | MutationEvent | UIEvent

Availability

HTML DOM Level 2

createProcessingInstruction(String target, String data) : ProcessingInstruction

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

StringtargetName, or "target", of the processing instruction to create.
StringdataData to store in the processing instruction.

Using createProcessingInstruction

document.createProcessingInstruction(
                    'xml-stylesheet',
                    'href="docbook.xsl" type="text/xsl"'
                    );
Remarks
Creates a new ProcessingInstruction at the beginning of the current document using the specified target and data values.
Throws
Raises an INVALID_CHARACTER_ERR error if the specified target contains illegal characers.
Raises a NOT_SUPPORTED_ERR error if the current document is an HTML document.
See Also

ProcessingInstruction

Availability

HTML DOM Level 2 | W3C

createStyleSheet([String url,] [Number index]) : static styleSheet

Creates a new StyleSheet object.

StringurlURL to create the styleSheet object from. Default is to create an empty styleSheet. (optional)
NumberindexIndex in the document to add the styleSheet. Default is to add the styleSheet to the end of the document. (optional)

For examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/style.html

Remarks
IE only. Supported in IE4+.
See Also

styleSheet

createTextNode(String data) : static String

Creates a new Text node.

StringdataText to include in the Text node.

Using createTextNode

var newEle = document.createElement('b');
                    var newText = document.createTextNode('this text is bold');
                    newEle.appendChild(newText);

For additional examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/basics.html

Remarks
Creates a new Text node for insertion into the DOM tree. Text nodes represent text within a document as a child of another element, such as the document content that is displayed to the user.
Availability

HTML DOM Level 2 | W3C

elementFromPoint(Number x, Number y) : HTMLElement

Returns the element found at the specified x, y location in the document.

NumberxHorizontal (x) position (in pixels) of the element to return.
NumberyVertical (x) position (in pixels) of the element to return.

Remarks
IE only. Supported in IE4+.

execCommand(String command, [Boolean UI,] [Object value]) : static Boolean

Executes the specified command on the document.

StringcommandCommand to execute.
BooleanUISpecify true to display a user interface. Default is false. (optional)
ObjectvalueValue to assign, depending on the command. (optional)

focus() : static Object

Gives focus to the document and fires the onfocus event handler.

Remarks
IE only. Supported in IE5.5+.

getElementById(String id) : static HTMLElement

Returns the Element node that matches the given ID.

StringidId of the element to get.

Using getElementById

var emailproperty = document.getElementById("email-textbox");
                    var emailAddress = emailproperty.getAttribute("value");

For additional examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/basics.html

Remarks

Use getElementById to avoid traversing multiple child nodes to retrieve a value.

Use a naming convention to assign unique Element id's so that you can easily retrieve information from the object model of your document without having add the id's later.

The DOM Level 2 Core specification does not define specific behavior for multiple elements with the same id, but Mozilla-based browsers will return the first element with specified id.

See Also

Document.getElementsByTagName | Element.getElementsByTagName | HTMLDocument.getElementsByName

Availability

HTML DOM Level 2 | W3C

getElementsByTagName(String tagname) : static Array

Returns an array of Element nodes with the specified tag name.

StringtagnameTag name of the elements to return. Specify "*" to return all tags. (one-or-more)

Using getElementsByTagName

// Assume there is only one  in the document
                    var body = document.getElementsByTagName("body").item(0);
                    var paragraphs = body.getElementsByTagName("p");

For additional examples, see the quirksmode test page:

http://www.quirksmode.org/dom/tests/basics.html

Remarks

Returns a list of elements in the document that have the specified tagName. The returned NodeList is sorted in the order the elements were found during a depth-first preorder traversal through the node tree.

See Also

Document.getElementById | Element.getElementsByTagName | HTMLDocument.getElementsByName

Availability

HTML DOM Level 2 | W3C

getElementsByTagNameNS(String namespaceURI, String localName) : static Array

Returns the Element nodes with the specified element name and namespace.

StringnamespaceURINamespace of the elements to return. Specify "*" to return all tags.
StringlocalNameTag name of the elements to return (minus the namespace prefix). Specify "*" to return all tags.

Using getElementsByTagNameNS

var commands = document.getElementsByTagNameNS(
                    'http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul',
                    'command'
                    );
Remarks

Like getElementsByTagName, this method returns a NodeList of elements found in the current document that match the specified tag name. However, this version of the method takes both a namespace URI and local name of the element's tag name.

See Also

getElementsByTagName

Availability

HTML DOM Level 2 | W3C

getSelection() : String

Returns the text currently selected by the user.

Remarks
Netscape only. Supported in NS4+.

importNode(Object importedNode, Boolean deep) : static Node

Imports a node from a different document.

ObjectimportedNodeNode to import.
BooleandeepIf true, indicates that all child nodes of the import node should be imported as well.

Remarks
importNode is similar to cloneNode, except that importNode works across documents. importNode attempts to copy as much information about a node as possible, although different documents may be of different types (e.g. XML and HTML) or have different DTD's.
Throws
Raises a NOT_SUPPORTED_ERR error if the node type being imported is not supported by the current document.
See Also

Node.cloneNode

Availability

HTML DOM Level 2 | W3C

isSupported(String feature, [String version]) : Boolean

Returns true if the specified feature and version are supported.

StringfeatureName of the feature.
StringversionVersion of the feature. (optional)

Remarks
Tests whether a node supports the specified feature. Similar to the DOMImplementation.hasFeature method and takes the same feature names. If version is null, returns true if any version of the feature is supported.
See Also

DOMImplementation.hasFeature

Availability

HTML DOM Level 2

open([String mimeType,] [String name,] [String features,] [Boolean replace]) : void

Opens the document for writing.

StringmimeTypeMIME Type for the new document. IE only. (optional)
StringnameSpecifies the new name for the document. Always use with mimeType. IE only. (optional)
StringfeaturesSpecifies any window-like features the document should have. Always use with mimeType. IE only. (optional)
BooleanreplaceIf true, specifies that the new document should replace the current document in the browser history. Always use with mimeType. IE only. (optional)

Remarks
Only use the parameters mimeType, name, features, and replace with IE. If you use any of the parameters, mimeType becomes a required parameter. If you are not coding strictly for IE, do not pass any parameters to the open method.
Availability

HTML DOM Level 1

queryCommandEnabled(String command) : Boolean

Returns true if the specified command is enabled.

StringcommandCommand to check.

See Also

queryCommandIndeterm | queryCommandState | queryCommandSupported | queryCommandValue

quertyCommandIndeterm(String command) : Boolean

Returns true if the specified command is in an indeterminate state.

StringcommandCommand to check.

See Also

queryCommandEnabled | queryCommandState | queryCommandSupported | queryCommandValue

queryCommandState(String command) : Boolean

Returns true if the specified command has been executed on the object.

StringcommandCommand to check.

See Also

queryCommandEnabled | queryCommandIndeterm | queryCommandSupported | queryCommandValue

queryCommandSupported(String command) : Boolean

Returns true if the specified command is supported.

StringcommandCommand to check.

See Also

queryCommandEnabled | queryCommandIndeterm | queryCommandState | queryCommandValue

queryCommandValue(String command) : Object

Returns the value of the specified command for the document. Returns false if the command is not supported.

StringcommandCommand to check.

See Also

queryCommandEnabled | queryCommandIndeterm | queryCommandState | queryCommandSupported

recalc([Boolean forceAll]) : void

Reevaluates all dynamic properties in the document.

BooleanforceAllIf true, forces all dynamic properties in the document to be reevaluated. If false (default), reevaluates only the dynamic properties that have changed. (optional)

releaseEvents(Number eventMask) : Object

Sets the document to stop capturing the specified type of events.

NumbereventMaskBitmask containing the events to stop capturing.

Remarks
Netscape only. Supported in NS4+.
See Also

captureEvents

routeEvent(Object event) : Object

Routes the specified event to the next event handler.

ObjecteventInstance of the event to route.

Remarks
Netscape only. Supported in NS4+.
See Also

captureEvents | releaseEvents

selection() : Object

Gives information about the currently selected objects in the document.

Remarks
IE only. Supported in IE4+.

write(String string) : Object

Writes the specified string of text to the end of the document.

StringstringText to append to the document. (one-or-more)

Using write

 document.write("Today's date is " + new Date()); 
See Also

writeln

Availability

HTML DOM Level 1 | W3C

writeln(String string) : Object

Writes the specified string of text to the end of the document and adds a newline character at the end of the text.

StringstringText to append to the document. (one-or-more)

Using write

 document.writeln("Today's date is " + new Date()); 
See Also

write

Availability

HTML DOM Level 1 | W3C