HTML DOM appendChild() method
Example
Add a list item:
document.getElementById("myList").appendChild(
newListItem
);
Before adding:
- Coffee
- Tea
After adding:
- Coffee
- Tea
- Water
Try it »
Definition and Usage
The appendChild() method adds a new child node to the end of the list of child nodes of a node.
**Note:** If newchild already exists in the document tree, it will be removed from the document tree and then re-inserted at its new position. If newchild is a DocumentFragment node, it will not be inserted directly; instead, its child nodes are inserted in order at the end of the current node's childNodes[] array.
You can use the appendChild() method to move an element to another element.
Example
Move a list item to another list item:
var node=document.getElementById("myList2").lastChild;
document.getElementById("myList1").appendChild(node);
Before adding:
-
Coffee
-
Tea
-
Water
-
Milk
After adding:
-
Coffee
-
Tea
-
Milk
-
Water
Try it »
Browser support





All major browsers support the appendChild() method
Syntax
node
.appendChild(
node
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| node | Node object | Required. The node object you want to add. |
Return Value
| Type | Description |
|---|---|
| Node object | The added node |
Technical Details
| DOM version | Core Level 1 Node Object |
|---|
Element object