createlement add child code example
Example 1: create element javascript with id
var btn = document.createElement('div');
btn.setAttribute("id", "div1");
Example 2: create and append element in javascript
//create and append element
var node = document.createElement("LI"); // Create a <li> node
var textnode = document.createTextNode("Water"); // Create a text node
node.appendChild(textnode); // Append the text to <li>
document.getElementById("myList").appendChild(node);