HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM appendChild() Method

Element Object Reference Element Object

Example

Append an item in a list:

document.getElementById("myList").appendChild(newListItem);

Before appending:

  • Coffee
  • Tea

After appending:

  • Coffee
  • Tea
  • Water

Try it yourself »

Definition and Usage

The appendChild() method appends a node as the last child of a node.

Tip: If you want create a new paragraph, with text, remember to create the text as a Text node which you append to the paragraph, then append the paragraph to the document.

You can also use the appendChild() method to move an element from one element to another.

Example

Move a list item from one list to another:

var node=document.getElementById("myList2").lastChild;
document.getElementById("myList1").appendChild(node);

Before appending:

  • Coffee
  • Tea
  • Water
  • Milk

After appending:

  • Coffee
  • Tea
  • Milk
  • Water

Try it yourself »

Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The appendChild() method is supported in all major browsers.


Syntax

node.appendChild(node)

Parameters

Parameter Type Description
node Node object Required. The node object you want to append

Return Value

Type Description
Node object The appended node

Technical Details

DOM Version Core Level 1 Node Object


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE