Wrox Home  
Search
Web Standards Programmer's Reference: HTML, CSS, JavaScript, Perl, Python, and PHP


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.
PropertyDescription
attributesThis read-only property returns a named node mapNamedNodeMap containing the specified node's attributes.
childNodesThis read-only property returns a node list containing all the children of the specified node.
firstChildThis read-only property returns the first child node of the specified node.
lastChildThis read-only property returns the last child node of the specified node.
nextSiblingThis read-only property returns the next sibling of the specified node.
nodeNameThis 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).
nodeTypeThis read-only property returns a number corresponding to the node type (1 = element, 2 = text).
nodeValueThis property returns a string containing the contents of the node and is only valid for text nodes.
ownerDocumentThis read-only property returns the root document node object of the specified node.
parentNodeThis read-only property returns the parent node of the specified node.
previousSiblingThis 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.

MethodDescription
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.
Page 1 | Page 2 | Page 3