Change Language


Follow Navioo On Twitter

Document : Node

Represents an HTML or XML document.

Platform Support

IE Mozilla Netscape Opera Safari
3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Constructors

Constructor Action IE Mozilla Netscape Opera Safari
Document Constructor() : Document
Creates a new instance of a Document object.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Document() : Document

Creates a new instance of a Document object.

Returns

Document
Visibility
internal

Inherited Properties

Property Action IE Mozilla Netscape Opera Safari
attributes : NamedNodeMap
Attributes for an element node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/dhtml/getAttributeNode_Example_4496.html

Remarks

This property returns a listing of all the attributes bound to this Node. Since only Element nodes support attributes, most Node types will return a null value for this property.

NamedNodeMaps are essentially the DOM-equivilant of a hash. This property provides an alternative to the specific Element.getAttribute and Element.hasAttribute methods, which are usually used when you already know which attributes an element has. For those circumstances when you want to do some automatic discovery of attributes and their values, this property provides a convenient way to iterate through the element's attributes.

This property also has the added benefit of being usable across all nodes, not just Element nodes. Therefore no checking needs to be done ahead of time to verify if a node is an Element; rather you can iterate over the attributes list, since any element that has no attributes, or any other DOM node, will have a null value for this property.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

childNodes : NodeList
Child nodes of the current node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/dhtml/createTextNode_Example_4484.html

Remarks

The list of nodes that are immediate children of this node. The DOM is a heirarchial structure of Node objects. This property, combined with the parentNode properties provide the basics for defining this structure. Several convenience properties are provided for accessing some frequently-used children nodes, namely the firstChild and lastChild properties.

Since the NodeList class can be referenced as an array as well as its object-oriented interface, one can easily iterate through the contents of a node using standard JavaScript for loops. Because this property is read-only, you cannot alter the NodeList to effect this node's contents. Instead, the methods for addeding and removing nodes should be used, which will result in this being updated automatically.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

firstChild : Node
First child node of the current node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/TreeWalker_425.htm

Remarks

Returns the first child node from the list of the current node's children. If this node doesn't have any children, a null value will be returned.

This is functionally equivilant to invoking node.childNodes.NodeList.item(0), though this method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

lastChild : Node
Last child node of the current node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/TreeWalker_425.htm

Remarks

Returns the last child node from the list of the current node's children. If this node doesn't have any children, a null value will be returned.

This is functionally equivilant to invoking node.childNodes.NodeList.item(node.childNodes.NodeList.length - 1), though this method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

localName : String
Local part of an element or attribute name if it the node was defined with an XML Namespace.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
Availability

HTML DOM Level 2|W3C

namespaceURI : String
URI of the namespace for an element or attribute node if the node was defined with an XML Namespace.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
Availability

HTML DOM Level 2|W3C

nextSibling : Node
Sibling node immediately after the current node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/TreeWalker_425.htm

Remarks

Returns the next node to the current one within the parent node's children. If this node is the last child within it's parent, then a null value will be returned.

When working with a node, it is often useful to be able to manipulate or search the nodes surrounding it. For instance, if given a node representing a label, you might want to find the text node immediately next to it. To help with this, the nextSibling property allows you to traverse to neighboring nodes in the DOM.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

nodeName : String
Name of the node. Same as tag name for element nodes.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/DOM_Node_403.dhtml

Remarks

This returns a name that represents this node's name. Depending on the type of object this is, this property will either return the name identifying this object; for instance, if this node is a Element or Attr object, then the tag or attribute name is returned. In other cases some place-holder text will be returned.

<property>nodeName</property> node-type valuesTypeleftValueleftAttr Attribute name CDATASection#cdata-sectionComment#commentDocument#documentDocumentFragment#document-fragmentDocumentType Document type name Element Tag name Entity Entity name EntityReference Name of entity referenced Notation Notation name ProcessingInstruction Target Text#text

If XML Namespaces were defined for this node and this node is a Element or Attr object (since these are the only node types that support the use of namespaces), this property returns the node name including the prefix and localName.

Returns an upper case tag name.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

nodeType : Number
Type of node. See Remarks for valid values.
Show Details 5.5+ 1.0+ 6.0+ 7.0+ 1.0+
  • IE: IE 5.0 on Windows does not assign nodeType attributes. Fixed in IE 5.5.

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/DOM_Node_403.dhtml

Remarks

This property returns an integer indicating what type of DOM Node this object represents.

Because the Node class is inherited by several other, more specific DOM objects, this property is a programmatic way of determining what an arbitrary node is, and therefore can tell the programmer how to interact with it. There are a series of constants defined in this object that can be used to refer to this property:

<property>nodeList</property> constant valuesValuerightConstantleft1ELEMENT_NODE2ATTRIBUTE_NODE3TEXT_NODE4CDATA_SECTION_NODE5ENTITY_REFERENCE_NODE6ENTITY_NODE7PROCESSING_INSTRUCTION_NODE8COMMENT_NODE9DOCUMENT_NODE10DOCUMENT_TYPE_NODE11DOCUMENT_FRAGMENT_NODE12NOTATION_NODE
Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

nodeValue : String
Value of the current node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/DOM_Node_403.dhtml

Remarks

This represents the value of the node. Only Attr, CDATASection, Comment, ProcessingInstruction, and Text objects can contain a value in this property. For all other types of objects this property will return null, and setting it to a different value has no effect.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

ownerDocument : Document
Document object that contains this node.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Document_290.dhtml

Remarks

Refers to the Document object that this node exists in. Because a node must be created as a child of a Document, and since Node objects cannot be moved arbitrarily from one document to another (not without duplicating it), this is a way of referring to the parent document for a node so that document-wide method calls can be used for a node.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

parentNode : Node
Parent node of the current node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/TreeWalker_425.htm

Remarks

This property contains a reference to the parent node for the current node. Since the DOM is a heirarchial structure of nodes, the parentNode and childNodes properties tie the collection of nodes together.

Not all nodes can have parents however. Attr, Document, DocumentFragment, Entity and Notation objects and as such will contain a null value for this property. As well this property will be null for newly-created nodes that have yet to be added to a location within the DOM tree.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

prefix : String
Namespace prefix for an element or attribute node if the node was defined with an XML Namespace.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+
Availability

HTML DOM Level 2|W3C

Sibling node immediately before the current node.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/TreeWalker_425.htm

Remarks
Returns the previous node to the current one within the parent node's children. If this node is the first child within it's parent, then a null value will be returned.
Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

Properties

Property Action IE Mozilla Netscape Opera Safari
activeElement : Element
Reference to the Element that currently has focus.
No Details 4.0+ no no no no
alinkColor : String
Specifies the color of active links.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
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

anchors : Array
Array of all of the Anchor objects in a document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
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

applets : Array
Array of all of the Applet objects in a document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Remarks
Because the Applets array is read-only, modify the array by adding and deleting applet elements.
Availability

HTML DOM Level 1

bgColor : String
Background color of a document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
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

body : Element
Reference to the body or frameset element.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Document_290.dhtml

Remarks

For additional compatibility information, see the quirksmode page:

http://www.navioo.com/javascript/tutorials/Source_File_5.htm

Availability

HTML DOM Level 1

charset : String
Character set of the document.
No Details 4.0+ no no no no
characterSet : String
Character set of the document.
No Details no 1.0+ 6.0+ no 1.0+
classes : Array
Array of style properties for CSS classes.
No Details no no 4.0+ no no
compatMode : Boolean
Indicates whether the document has standards-compliant mode turned on.
Show Details 6.0+ 1.75+ 7.0+ no no

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Source_File_5.htm

cookie : String
Value of the cookie that the browser has set for the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Availability

HTML DOM Level 1

defaultCharset : String
Default character set for the document.
No Details 4.0+ no no no no
designMode : String
Specifies that design mode for an HTML document is "on" or "off."
Show Details 5.0+ 1.4+ 7.0+ no no
Remarks
If design mode is on, a user can double-click the document to edit its HTML.
dir : String
Text direction of the content in the document.
Show Details 5.0+ 1.0+ 6.0+ no no

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/HTML_Tags_371.dhtml

Availability

HTML DOM Level 0

doctype : DocumentType
Document Data Type (DTD) associated with this document.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ no
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

documentElement : Element
Root element in a document.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Document_290.dhtml

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

domain : String
Internet domain of the document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Availability

HTML DOM Level 1

embeds : Array
Array of all embedded objects in the document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
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

expando : Boolean
Indicates whether a client-side object may have instance properties added to it.
Show Details 4.0+ no no no no
Remarks
Use expando to help catch typos and case-sensitivity issues in your JavaScript.
fgColor : String
Font color of the document text.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
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

fileCreatedDate : String
Date that the document was created.
No Details 4.0+ no no no no
fileModifiedDate : String
Date that the document was last modified.
No Details 4.0+ no no no no
fileSize : Number
File size (in bytes) of the document.
No Details 4.0+ no no no no
forms : Array
Array of all of the Forms in the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Although the Forms array is read-only, you can modify the individual Form elements.
Availability

HTML DOM Level 1

frames : Array
Array of all of the Frames in the document.
Show Details 4.0+ no no no no
Remarks
Although the Frames array is read-only, you can modify the individual Frame elements.
height : Number
Height of the entire HTML document (in pixels).
No Details no 1.0+ 4.0+ 7.0+ 1.0+
ids : Array
Array of style properties in the document set by the Id attribute.
Show Details no no 4.0+ no no
Remarks
Although the Ids array is read-only, you can modify the individual Id elements.
images : Array
Array of Image objects in the document.
Show Details 4.0+ 1.0+ 3.0+ 7.0+ 1.0+
Remarks
Although the Images array is read-only, you can modify the individual Image elements.
Availability

HTML DOM Level 1

implementation : Object
Object that specifies whether or not and at what level the browser supports the specified feature.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+
Availability

HTML DOM Level 2|W3C

lastModified : String
Date that the document was last modified.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Availability

HTML DOM Level 0

layers : Array
Array of all of the Layer elements in the document.
Show Details no no 4.0+ no no
Remarks
Includes divs positioned by CSS.
linkColor : String
Color of the unvisited links in the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
See Also

HTMLBodyElement

Availability

HTML DOM Level 0

links : Array
Array of all of the links in the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
Remarks
Although the Link array is read-only, you can modify the individual Link elements.
Availability

HTML DOM Level 1

location : Object
Complete URL of the document.
Show Details 3.0+ no 3-4 no no
Remarks
Deprecated for Window.location.
See Also

Window.location

media : String
The media that the document is intended for.
No Details 5.5+ no no no no
mimeType : String
Information about the document MIME type.
No Details 5.0+ no no no no
namespaces : Array
Array of the XML Namespaces for a document.
No Details 5.5+ no no no no
onactivate : Function
Fires when the element becomes active.
No Details 4.0+ no no no no
onbeforecut : Function
Fires immediately before the selection is cut to the clipboard.
No Details 4.0+ no no no 1.0+
onbeforedeactivate : Function
Fires immediately before the element stops being the active element.
No Details 4.0+ no no no no
onbeforeeditfocus : Function
Fires immediately before the element receives focus prior to being edited.
No Details 4.0+ no no no no
onbeforepaste : Function
Fires immediately before the selection is pasted from the clipboard to the element.
No Details 4.0+ no no no 1.0+
onclick : Function
Fires when the element is clicked.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
oncontextmenu : Function
Fires when the element is right-clicked and the context menu opens.
No Details 4.0+ no no no 1.0+
oncontrolselect : Function
Fires immediately before the element is selected.
No Details 4.0+ no no no no
oncut : Function
Fires when the element is cut to the clipboard.
No Details 4.0+ no no no 1.0+
ondblclick : Function
Fires when the element is double-clicked.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
ondrag : Function
Fires when the element is dragged.
No Details 4.0+ no no no 1.0+
ondragend : Function
Fires when the element is released from being dragged.
No Details 4.0+ no no no 1.0+
ondragenter : Function
Fires when the element has another object dragged onto it that can be dropped on the element.
No Details 4.0+ no no no 1.0+
ondragleave : Function
Fires when an element has an object dragged out of it that could be dropped onto the element.
No Details 4.0+ no no no 1.0+
ondragover : Function
Fires when an element has an object dragged over it that could be dropped onto the element.
No Details 4.0+ no no no 1.0+
ondragstart : Function
Fires immediately before an element is dragged.
No Details 4.0+ no no no 1.0+
ondrop : Function
Fires when an object is dropped onto the element.
No Details 4.0+ no no no 1.0+
onhelp : Function
Fires when a user presses the F1 key to activate help.
No Details 4.0+ no no no no
onkeydown : Function
Fires when a user presses down on a key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onkeypress : Function
Fires when a user presses a key or holds down the key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onkeyup : Function
Fires when a user releases a key while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmousedown : Function
Fires when a user clicks down on the mouse button while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmousemove : Function
Fires when the mouse moves while the pointer over the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseout : Function
Fires when the mouse pointer moves off of the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseover : Function
Fires when the mouse pointer moves over the element.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onmouseup : Function
Fires when the user releases the mouse button while the element has focus.
No Details 2.0+ 1.0+ 1.0+ 4.0+ 1.0+
onpaste : Function
Fires when the clipboard contents are pasted onto the element.
No Details 4.0+ no no no 1.0+
onpropertychange : Function
Fires when one of the properties of the element changes.
No Details 4.0+ no no no no
onreadystatechange : Function
Fires when the ready state of the element changes.
No Details 4.0+ no no no no
onresize : Function
Fires immediately before an element is about to be resized.
No Details 4.0+ no no no 1.0+
onresizeend : Function
Fires when the element is finished being resized.
No Details 4.0+ no no no no
onresizestart : Function
Fires immediately before a user resizes the element.
No Details 4.0+ no no no no
onselectionchange : Function
Fires when the selected state of the document changes.
No Details 5.5+ no no no no
onstop : Function
Fires when a user clicks the Stop button on the browser.
No Details 5.5+ no no no no
parentWindow : Object
Reference to the parent Window of the document.
Show Details 4.0+ no no 8.0+ no

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Window_353.dhtml

See Also

Window

plugins : Array
Array of plugins installed in the browser.
Show Details 2.0+ 1.0+ 1.0+ 7.0+ 1.0+
Remarks
Synonym for the embeds[] array.
See Also

Document.embeds

protocol : String
Full name of the protocol (not "http") used to retrieve the document.
Show Details 4.0+ no no no no
Remarks
IE only. Supported in IE4+.
referrer : String
URL of the referring document.
Show Details 2.0+ 1.0+ 1.0+ 7.0+ 1.0+
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

scripts : Array
Array of all of the Scripts in the document.
No Details 4.0+ no no no no
security : String
Information about the security certificate for the document.
No Details 5.5+ no no no no
selection : Object
Object representing any currently selected text.
No Details 4.0+ no no no no
styleSheets : Array
Array of all of the styleSheets in the document.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.2+
  • Safari: Cannot access disabled or alternate stylesheets.

For examples, see the Navioo examples page:

http://www.navioo.com/html_css/CSS_Attributes_and_Javascript_Style_Properties_142.dhtml

Availability

HTML DOM Level 2

tags : Array
Array of style properties for certain HTML tags.
No Details no no 4.0+ no no
title : String
Title of the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/dhtml/innerHTML_Example_4506.html

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

HTML DOM Level 1

URL : String
URL of the document.
Show Details 4.0+ 1.0+ 2.0+ no no
See Also

location.href

URLUnencoded : String
URL-unencoded version of the URL.
Show Details 5.5+ no no no no
See Also

Document.URL

vlinkColor : String
Color of visited links.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+
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

width : Number
Width of the HTML document (in pixels).
No Details no 1.0+ 4.0+ 7.0+ 1.0+
XMLDocument : Object
Reference to the top-level node of the XML DOM used by the document.
No Details 5.0+ no no no no
XSLDocument : Object
Reference to the XSL document for the document.
No Details 5.0+ no no no no

Inherited Functions

Method Action IE Mozilla Netscape Opera Safari
hasAttributes() : Boolean
Returns true if the node is an element node with attributes.
Show Details no 1.0+ 6.0+ 7.0+ 1.3+

Returns

Boolean

Using hasAttributes

var obj = document.Document.getElementById('EmailAddress');
                        if (obj.hasAttributes()) {
                        window.alert("The node " + obj.Node.nodeName + " has attributes");
                        }

For more examples, see the Navioo examples page:

http://www.navioo.com/javascript/dhtml/getAttributeNode_Example_4496.html

Remarks
Returns true if this node is an Element and has any attributes. Returns false if there are none. Equivilant to checking node.attributes.NamedNodeMap.length > 0.
See Also

Element.getAttribute|Element.hasAttribute|Node.attributes

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

hasChildNodes() : Boolean
Returns true if the node has child nodes.
Show Details 4.0+ 1.0+ 6.0+ 7.0+ 1.0+

Returns

Boolean

Using hasChildNodes

var obj = document.Document.getElementById('EmailAddress');
                        if (obj.hasChildNodes()) {
                        window.alert("The node " + obj.Node.nodeName + " has children");
                        }
Remarks
Returns true if this node has any child nodes. Returns false if there are none. Equivilant to checking node.childNodes.NodeList.length > 0.
See Also

Node.childNodes

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

isSupported(String feature, [String version]) : Boolean
Returns true if the specified feature and version are supported.
Show Details no 1.0+ 6.0+ 7.0+ 1.0+

Parameters

String feature Name of the feature.
String version (optional)Version of the feature.

Returns

Boolean
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|W3C

normalize() : void
Merges text nodes adjacent to the element to create a normalized DOM.
Show Details N/A 1.0+ 6.0+ 7.0+ 1.0+
  • IE: May crash IE 6.0.

Returns

void

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Stringsplit_283.html

Remarks
Normalizes any Text nodes contained under this node and all of its children. Merges any adjacent Text nodes into one object, so that the nodes reflect how they would be structured if this XML document were freshly loaded.

Normalize() is useful for manipulating the text content of nodes for editing. Instead of worrying about altering existing Text nodes, you can simply add new nodes and perform the normalize when you finish your updates.

Availability

HTML DOM Level 1|HTML DOM Level 2|W3C

Functions

Method Action IE Mozilla Netscape Opera Safari
captureEvents(Number eventMask) : void
Sets an document to capture the events specified by eventMask.
Show Details no no 4.0+ no no

Parameters

Number eventMask Bitmask containing the events to capture.

Returns

void
Remarks
Supported in Mozilla and NS4+.
See Also

releaseEvents

clear() : void
Clears the content from the document.
Show Details 3.0+ 1.0+ 2.0+ no 1.0+

Returns

void
close() : Object
Stops the output stream to the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Returns

Object
Availability

HTML DOM Level 0

contextual(String context) : void
Sets a concept to select tags to style.
Show Details no no 4.0 no no

Parameters

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

Returns

void
static createAttribute(String name) : Attr
Creates a new Attr node
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • Safari: Safari will create the attribute, but you will have to use nodeValue to set its value.

Parameters

String name Name of the attribute to create.

Returns

Attr

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 Navioo examples page:

http://www.navioo.com/javascript/dhtml/getAttributeNode_Example_4496.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

static createAttributeNS(String namespaceURI, String qualifiedName) : Attr
Creates a new Attr using a namespace.
Show Details 6.0+ 1.0+ 6.0+ 7.0+ 1.0+

Parameters

String namespaceURI The namespace of the new attribute.
String qualifiedName The qualified name (e.g. rdf:about) of the attribute to create.

Returns

Attr
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
Show Details no 1.0+ no no no

Parameters

Object data The text to wrap up into a new CDATASection object.

Returns

CDATASection

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
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Parameters

String data The text to include in the comment.

Returns

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
Show Details 6.0+ 1.0+ 2.0+ 7.0+ 1.0+

Returns

DocumentFragment

For examples, see the Navioo examples page:

http://www.navioo.com/javascript/dhtml/createDocumentFragment_Example_4479.html

Availability

HTML DOM Level 2|W3C

static createElement(String tagName) : HTMLElement
Creates a new Element node of the type specified by tagName (e.g. li element.)
Show Details 5.0+ 1.75+ 6.0+ 8.0+ 1.3+
  • IE: IE also supports the syntax "createElement('&lt;p&gt;')".

Parameters

String tagName The tag name of the element to be created.

Returns

HTMLElement

Using createElement

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

For additional examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Document_290.dhtml

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

static createElementNS(String namespaceURI, String qualifiedName) : HTMLElement
Creates a new Element node with a namespace.
Show Details no 1.0+ 6.0+ 9.0+ 1.3+

Parameters

String namespaceURI Namespace of the new element.
String qualifiedName Qualified name (e.g. myns:element) of the element to create.

Returns

HTMLElement

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

static createEntityReference(String name) : EntityReference
Creates a new EntityReference object
Show Details no 1.0+ no no no

Parameters

String name Name of the new entity reference.

Returns

EntityReference
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

static createEventObject(String eventObj) : Event
Creates a new Event object to be used by the fireEvent method.
Show Details 5.0+ no no no no

Parameters

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

Returns

Event
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.
Show Details no 1.0+ no no no

Parameters

String target Name, or "target", of the processing instruction to create.
String data Data to store in the processing instruction.

Returns

ProcessingInstruction

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

static createStyleSheet([String url,] [Number index]) : styleSheet
Creates a new StyleSheet object.
Show Details 4.0+ no no no no

Parameters

String url (optional)URL to create the styleSheet object from. Default is to create an empty styleSheet.
Number index (optional)Index in the document to add the styleSheet. Default is to add the styleSheet to the end of the document.

Returns

styleSheet

For examples, see the Navioo examples page:

http://www.navioo.com/html_css/CSS_Attributes_and_Javascript_Style_Properties_142.dhtml

Remarks
IE only. Supported in IE4+.
See Also

styleSheet

static createTextNode(String data) : String
Creates a new Text node.
Show Details 5.0+ 1.75+ no 8.0+ 1.3+

Parameters

String data Text to include in the Text node.

Returns

String

Using createTextNode

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

For additional examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Document_290.dhtml

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.
Show Details 4.0+ no no no no

Parameters

Number x Horizontal (x) position (in pixels) of the element to return.
Number y Vertical (x) position (in pixels) of the element to return.

Returns

HTMLElement
Remarks
IE only. Supported in IE4+.
static execCommand(String command, [Boolean UI,] [Object value]) : Boolean
Executes the specified command on the document.
Show Details 4.0+ 1.4+ 7.1+ no no

Parameters

String command Command to execute.
Boolean UI (optional)Specify true to display a user interface. Default is false.
Object value (optional)Value to assign, depending on the command.

Returns

Boolean
static focus() : Object
Gives focus to the document and fires the onfocus event handler.
Show Details 5.5+ no no no no

Returns

Object
Remarks
IE only. Supported in IE5.5+.
static getElementById(String id) : HTMLElement
Returns the Element node that matches the given ID.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • 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".

Parameters

String id Id of the element to get.

Returns

HTMLElement

Using getElementById

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

For additional examples, see the Navioo examples page:

http://www.navioo.com/javascript/tutorials/Document_290.dhtml

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

static getElementsByTagName(String tagname) : Array
Returns an array of Element nodes with the specified tag name.
Show Details 5.0+ 1.0+ 6.0+ 7.0+ 1.0+
  • IE: Does not work in IE 5.0 on Windows.

Parameters

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

Returns

Array

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 Navioo examples page:

http://www.navioo.com/javascript/tutorials/Document_290.dhtml

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

static getElementsByTagNameNS(String namespaceURI, String localName) : Array
Returns the Element nodes with the specified element name and namespace.
Show Details no 1.0+ no no no

Parameters

String namespaceURI Namespace of the elements to return. Specify "*" to return all tags.
String localName Tag name of the elements to return (minus the namespace prefix). Specify "*" to return all tags.

Returns

Array

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.
Show Details no no 4.0+ no no

Returns

String
Remarks
Netscape only. Supported in NS4+.
static importNode(Object importedNode, Boolean deep) : Node
Imports a node from a different document.
Show Details no 1.0+ no no no

Parameters

Object importedNode Node to import.
Boolean deep If true, indicates that all child nodes of the import node should be imported as well.

Returns

Node
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.
Show Details no 1.0+ 6.0+ no no

Parameters

String feature Name of the feature.
String version (optional)Version of the feature.

Returns

Boolean
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.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Parameters

String mimeType (optional)MIME Type for the new document. IE only.
String name (optional)Specifies the new name for the document. Always use with mimeType. IE only.
String features (optional)Specifies any window-like features the document should have. Always use with mimeType. IE only.
Boolean replace (optional)If true, specifies that the new document should replace the current document in the browser history. Always use with mimeType. IE only.

Returns

void
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.
Show Details 4.0+ 1.4+ 7.1+ no no

Parameters

String command Command to check.

Returns

Boolean
See Also

queryCommandIndeterm|queryCommandState|queryCommandSupported|queryCommandValue

quertyCommandIndeterm(String command) : Boolean
Returns true if the specified command is in an indeterminate state.
Show Details 4.0+ 1.4+ 7.1+ no no

Parameters

String command Command to check.

Returns

Boolean
See Also

queryCommandEnabled|queryCommandState|queryCommandSupported|queryCommandValue

queryCommandState(String command) : Boolean
Returns true if the specified command has been executed on the object.
Show Details 4.0+ 1.4+ 7.1+ no no

Parameters

String command Command to check.

Returns

Boolean
See Also

queryCommandEnabled|queryCommandIndeterm|queryCommandSupported|queryCommandValue

queryCommandSupported(String command) : Boolean
Returns true if the specified command is supported.
Show Details 4.0+ 1.4+ 7.1+ no no

Parameters

String command Command to check.

Returns

Boolean
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.
Show Details 4.0+ 1.4+ 7.1+ no no

Parameters

String command Command to check.

Returns

Object
See Also

queryCommandEnabled|queryCommandIndeterm|queryCommandState|queryCommandSupported

recalc([Boolean forceAll]) : void
Reevaluates all dynamic properties in the document.
Show Details 5.0+ no no no no

Parameters

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

Returns

void
releaseEvents(Number eventMask) : Object
Sets the document to stop capturing the specified type of events.
Show Details no no 4.0+ no no

Parameters

Number eventMask Bitmask containing the events to stop capturing.

Returns

Object
Remarks
Netscape only. Supported in NS4+.
See Also

captureEvents

routeEvent(Object event) : Object
Routes the specified event to the next event handler.
Show Details no no 4.0+ no no

Parameters

Object event Instance of the event to route.

Returns

Object
Remarks
Netscape only. Supported in NS4+.
See Also

captureEvents|releaseEvents

selection() : Object
Gives information about the currently selected objects in the document.
Show Details 4.0+ no no no no

Returns

Object
Remarks
IE only. Supported in IE4+.
write(String string) : Object
Writes the specified string of text to the end of the document.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Parameters

String string (one-or-more)Text to append to the document.

Returns

Object

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.
Show Details 3.0+ 1.0+ 2.0+ 7.0+ 1.0+

Parameters

String string (one-or-more)Text to append to the document.

Returns

Object

Using write

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

write

Availability

HTML DOM Level 1|W3C

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

text_javascript Navioo_docs

Examples -> Source code Demo online - > document:

Ajax Javascript feed

↑ Grab this Headline Animator