Favorites

DOM Node Interface

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Node
DOM InterfaceThis interface is supported by all modern browsers.
Updated 28th November 2026

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

NameDescription
Node.childNodesThe childNodes property returns a live list of all the child nodes of a node, including text and comments.
Node.firstChildThe firstChild property returns the first child node of a node, which may be a text node.
Node.nextSiblingThe nextSibling property returns the node immediately after a node in its parent, which may be a text node.
Node.nodeTypeThe 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.parentElementThe parentElement property returns the element that contains a node, or null.
Node.parentNodeThe parentNode property returns the parent of a node in the DOM tree.
Node.textContentThe textContent property gets or sets the text inside a node and its descendants.

Methods

NameDescription
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

<ul>
  <li>One</li>
  <li>Two</li>
</ul>
const list = document.querySelector('ul');
console.log(list.childNodes.length, list.children.length);
console.log(list.firstChild.nodeType, list.firstElementChild.nodeType);
console.log(list instanceof Node, list.firstChild instanceof Element);

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.

This interface is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee