Element appendChild() Method - Move a list item from one list to another: - Javascript DOM

Javascript examples for DOM:Element appendChild

Description

Element appendChild() Method - Move a list item from one list to another:

Demo Code

ResultView the demo in separate window

<!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() {//from ww  w. j ava2 s. c o m
    var node = document.getElementById("myList2").lastChild;
    document.getElementById("myList1").appendChild(node);
}
</script>

</body>
</html>

Related Tutorials