Javascript examples for DOM:Element appendChild
The appendChild() method appends a node to current element.
Parameter | Type | Description |
---|---|---|
node | Node object | Required. The node object you want to append |
A Node Object, representing the appended node
The following code shows how to Append an item in a list:
<!DOCTYPE html> <html> <body> <ul id="myList1"><li>Coffee</li><li>Tea</li></ul> <ul id="myList2"><li>Water</li><li>Milk</li></ul> <button onclick="myFunction()">Test</button> <script> function myFunction() {// w ww .ja v a 2 s . c o m var node = document.getElementById("myList2").lastChild; document.getElementById("myList1").appendChild(node); } </script> </body> </html>