DOM Node Properties and Methods
The DOM includes several JavaScript bindings that can be used to navigate a document's DOM. A subset of those bindings, used in JavaScript as properties and methods, is listed in the following two tables. The first table describes JavaScript's properties.
A full list of DOM JavaScript bindings can be found on the W3C's Document Object Model Level 1 pages, at http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ecma-script-language-binding.html.
| Property | Description |
attributes | This read-only property returns a named node mapNamedNodeMap containing the specified node's attributes. |
childNodes | This read-only property returns a node list containing all the children of the specified node. |
firstChild | This read-only property returns the first child node of the specified node. |
lastChild | This read-only property returns the last child node of the specified node. |
nextSibling | This read-only property returns the next sibling of the specified node. |
nodeName | This read-only property returns a string containing the name of the node, which is typically the name of the element (P, DIV, TABLE, and so on). |
nodeType | This read-only property returns a number corresponding to the node type (1 = element, 2 = text). |
nodeValue | This property returns a string containing the contents of the node and is only valid for text nodes. |
ownerDocument | This read-only property returns the root document node object of the specified node. |
parentNode | This read-only property returns the parent node of the specified node. |
previousSibling | This read-only property returns the previous sibling of the specified node. If there is no node, the property returns null. |
The second table describes JavaScript's methods.
| Method | Description |
appendChild(newChild) | Given a node, this method inserts the newChild node at the end of the children and returns a node. |
cloneNode(deep) | This method clones the node object. The parameter deep — (a Boolean) — specifies whether the clone should include the source object's attributes and children. The return value is the cloned node(s). |
hasChildNodes() | This method returns true if the node object has children nodes, false if the node object has no children nodes. |
insertBefore(newChild, refChild) | Given two nodes, this method inserts the newChild node before the specified refChild node and returns a node object. |
removeChild(oldChild) | Given a node, this method removes the oldChild node from the DOM and returns a node object containing the node removed. |
replaceChild(newChild, oldChild) | Given two nodes, this method replaces the oldChild node with the newChild node and returns a node object. Note that if the newChild is already in the DOM, it is removed from its current location to replace the oldChild. |
