How to Create and Insert New Element Using Javascript

Firstly, we need to create the new element and give it an ID so we can style it later on using CSS.

var btnn = document.createElement("div");   
btnn.innerHTML = "(+5 Days Delivery)";
btnn.id = "del";

We then need to Insert Into the Document – by finding parent and child element (by class) we can then use the appendChild function and insert it AFTER the child class contained within the Parent.

var tarP = document.getElementsByClassName('button-variable-item-ukas')[0];    
var tar = document.getElementsByClassName('variable-item-span variable-item-span-button')[0];
tarP.appendChild(btnn, tar);

Leave a Reply