DOM Node Interface
Node is the base interface for everything in the DOM tree, including elements, text and comments. It provides methods for moving through the tree and adding or removing nodes.
Description
The Node interface is the base for every object in the DOM tree: elements, text, comments, the document itself and document fragments. It provides what they have in common, such as parentNode, childNodes, textContent, appendChild(), removeChild(), cloneNode() and contains().
Node lists such as childNodes include text nodes, even for the white space between tags, which is why the element-only properties of Element, such as children and firstElementChild, are often more convenient. nodeType tells you what kind of node you have.
Every node knows its place in the tree through properties such as parentNode, firstChild, nextSibling and ownerDocument. Methods that move nodes, such as appendChild() and insertBefore(), remove a node from its old position first, because a node can only be in one place. isConnected tells you whether a node is currently part of a document, and compareDocumentPosition() tells you how two nodes relate to each other.
Inheritance
Node inherits properties and methods from EventTarget.
Properties
| Name | Description |
|---|---|
Node.childNodes | The childNodes property returns a live list of all the child nodes of a node, including text and comments. |
Node.firstChild | The firstChild property returns the first child node of a node, which may be a text node. |
Node.nextSibling | The nextSibling property returns the node immediately after a node in its parent, which may be a text node. |
Node.nodeType | The nodeType property returns a number that tells you what kind of node something is, such as 1 for an element or 3 for text. |
Node.parentElement | The parentElement property returns the element that contains a node, or null. |
Node.parentNode | The parentNode property returns the parent of a node in the DOM tree. |
Node.textContent | The textContent property gets or sets the text inside a node and its descendants. |
Methods
| Name | Description |
|---|---|
Node.appendChild() | The appendChild() method adds a node as the last child of an element. |
Node.cloneNode() | The cloneNode() method makes a copy of a node, optionally including all of its children. |
Node.contains() | The contains() method checks whether a node is inside another node (or is the same node). |
Node.insertBefore() | The insertBefore() method inserts a node into a parent element before a given child. |
Node.removeChild() | The removeChild() method removes a child node from its parent and returns it. |
Example
Browser Support
The following information will show you the current browser support for the Node interface. Hover over a browser icon to see the version that first introduced support for this interface.
Desktop





Tablets & Mobile





