Javascript DOM HTML UL append new <LI> element

Description

Javascript DOM HTML UL append new <LI> element

View in separate window

<!DOCTYPE html>
<html>
<body>

<ul id="myList">
  <li>CSS</li>
  <li>HTML</li>
</ul>/*from  w ww  .  ja  v a 2s .  co m*/
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  var node = document.createElement("LI");
  var textnode = document.createTextNode("Water");
  node.appendChild(textnode);
  document.getElementById("myList").appendChild(node);
}
</script>
</body>
</html>



PreviousNext

Related