Easy Tutorial
❮ Prop Loc Host Jsref Random ❯

HTML DOM appendChild() Method

Element Object

Example

Adding a list item:

Before adding:

After adding:


Definition and Usage

The appendChild() method adds a new child node to the end of the list of children of a specified node.

Note: If newchild already exists in the document tree, it is removed from the document tree and then reinserted at its new position. If newchild is a DocumentFragment node, it is not directly inserted; 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

Transferring a list item to another list:

Before adding:

After adding:


Browser Support

All major browsers support the appendChild() method.


Syntax

Parameters

Parameter 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

❮ Prop Loc Host Jsref Random ❯