Node Interface

In the DOM, all document parts are organized in a hierarchical tree-like structure consisting of parents and children. These individual parts are called Nodes. The Node interface is an abstract base class, so there is no such thing as a plain Node object. Look at some of the most used properties nodeType, parentNode, childNodes, firstChild, lastChild, previousSibling, nextSibling, and attributes.

Instance methods

In addition to the methods below, Node inherits methods from its parent, EventTarget.

Node.appendChild()

Adds the specified childNode argument as the last child to the current node. If the argument referenced an existing node on the DOM tree, the node will be detached from its current position and attached at the new position.

Node.cloneNode()

Clone a Node, and optionally, all of its contents. By default, it clones the content of the node.

Node.compareDocumentPosition()

Compares the position of the current node against another node in any other document.

Node.contains()

Returns true or false value indicating whether or not a node is a descendant of the calling node.

Node.getRootNode()

Returns the context object's root which optionally includes the shadow root if it is available.

Node.hasChildNodes()

Returns a boolean value indicating whether or not the element has any child nodes.

Node.insertBefore()

Inserts a Node before the reference node as a child of a specified parent node.

Node.isDefaultNamespace()

Accepts a namespace URI as an argument and returns a boolean value with a value of true if the namespace is the default namespace on the given node or false if not.

Node.isEqualNode()

Returns a boolean value which indicates whether or not two nodes are of the same type and all their defining data points match.

Node.isSameNode()

Returns a boolean value indicating whether or not the two nodes are the same (that is, they reference the same object).

Node.lookupPrefix()

Returns a string containing the prefix for a given namespace URI, if present, and null if not. When multiple prefixes are possible, the result is implementation-dependent.

Node.lookupNamespaceURI()

Accepts a prefix and returns the namespace URI associated with it on the given node if found (and null if not). Supplying null for the prefix will return the default namespace.

Node.normalize()

Clean up all the text nodes under this element (merge adjacent, remove empty).

Node.removeChild()

Removes a child node from the current element, which must be a child of the current node.

Node.replaceChild()

Replaces one child Node of the current one with the second one given in parameter.