2021-06-01 15:00:21 -04:00
<!DOCTYPE html>
< html >
< body >
< ul id = "myList" >
< li > Coffee< / li >
< li > Tea< / li >
< / ul >
< p > Click the button to append an item to the end of the list.< / p >
< button onclick = "myFunction()" > Try it< / button >
< script >
function myFunction() {
var node = document.createElement("LI");
var textnode = document.createTextNode("Water");
node.appendChild(textnode);
document.getElementById("myList").appendChild(node);
2021-11-10 12:05:35 -05:00
window.alert(document.getElementsByTagName("HTML")[0].outerHTML);
2021-06-01 15:00:21 -04:00
}
< / script >
< p > < strong > Note:< / strong > < br > First create an LI node,< br > then create a Text node,< br > then append the Text node to the LI node.< br > Finally append the LI node to the list.< / p >
< / body >
< / html >