DOM Node.appendChild() Method
The appendChild() method adds a node as the last child of an element. If the node is already in the page, it is moved.
Description
The appendChild() method adds a node to the end of the list of children of a parent node. A node can only be in one place, so appending a node that is already in the document moves it. Appending a DocumentFragment moves all of its children.
The newer append() method is more flexible: it accepts several nodes and plain strings at once. appendChild() returns the node, which can be handy for chaining.
It can only append one node at a time and only accepts nodes, not strings, so text must be wrapped in document.createTextNode(). Appending a node that is an ancestor of the parent throws a HierarchyRequestError, since that would create a loop in the tree.
Syntax
parent.appendChild(child)Parameters
- childThe node to add as the last child.
Return Value
The appended node.
Example
Browser Support
The following information will show you the current browser support for the Node.appendChild() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





