Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>The Element Object</h1>
<h2>The appendChild() Method</h2>
<ul id="myList">
  <li>Coffee</li>
  <li>Tea</li>
</ul>
<p>Click "Append" to append an item to the end of the list:</p>
<button onclick="myFunction()">Append</button>
<script>
function myFunction() {
// Create an "li" node:
const node = document.createElement("li");
// Create a text node:
const textnode = document.createTextNode("Water");
// Append the text node to the "li" node:
node.appendChild(textnode);
// Append the "li" node to the list:
document.getElementById("myList").appendChild(node);
}
</script>
</body>
</html>