js create and append element code example
Example 1: create and append element in javascript
var node = document.createElement("LI");
var textnode = document.createTextNode("Water");
node.appendChild(textnode);
document.getElementById("myList").appendChild(node);
Example 2: appendchild javascript
const parent = document.createElement('div');
const child = document.createElement('p');
parent.append(child)
parent.appendChild(child)
parent.append('Hello world')
parent.appendChild('Hello world')
Example 3: how to appendChild in the begin of the div javascript
var element = document.getElementById("div1");
element.insertBefore(para, element.firstChild);