insert html before element code example
Example 1: javascript add div before element
var my_elem = document.getElementById('my_id');
var span = document.createElement('span');
span.innerHTML = '*';
span.className = 'asterisk';
my_elem.parentNode.insertBefore(span, my_elem);
Example 2: js insert before
const alert_box = document.createElement("div")
alert_box.innerText = "Not allowed!";
alert_box.className = "alert";
const cont = document.querySelector(".container");
const prof = document.getElementById("profile");
cont.insertBefore(alert_box, prof);