dom insert element code example
Example 1: insert element to dom
var node = document.createElement("LI");
var textnode = document.createTextNode("Water");
node.appendChild(textnode);
document.getElementById("myList").appendChild(node);
Example 2: js insertbefore
let insertedNode = parentNode.insertBefore(newNode, referenceNode)
Example 3: appendchild javascript
const parent = document.createElement('div');
const child = document.createElement('p');
const childTwo = document.createElement('p');
parent.append(child, childTwo, 'Hello world');
parent.appendChild(child, childTwo, 'Hello world');
Example 4: add a child html object to another html object in js
parent.append(child);
parent.insertBefore(child, list.childNodes[0]);