JS - General HTML DOM

0 votes
96 views
added Aug 8, 2019 in Javascript by LC Marshal Captain (25,770 points)
// Create a <li> node
var newElem = document.createElement("LI");

// Create a text node
var textnode = document.createTextNode("Water"); 

// Append the text to <li>
newElem.appendChild(textnode);                    

// Get the <ul> element to insert a new node
var list = document.getElementById("myList");  

// Insert <li> before the first child of <ul>
list.insertBefore(newElem, list.childNodes[0]);  

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...