1// The Node.insertBefore() method inserts a node before a
2// reference node as a child of a specified parent node.
3let insertedNode = parentNode.insertBefore(newNode, referenceNode)
1// create alert div
2const alert_box = document.createElement("div")
3alert_box.innerText = "Not allowed!";
4alert_box.className = "alert";
5
6//get the parrent of where u wanna insert
7const cont = document.querySelector(".container");
8// get the element you wanna insert before
9const prof = document.getElementById("profile");
10// do the insert
11cont.insertBefore(alert_box, prof);
1<div id="parentElement">
2 <span id="childElement">foo bar</span>
3</div>
4
5<script>
6// Create a new, plain <span> element
7let sp1 = document.createElement("span")
8
9// Get the reference element
10let sp2 = document.getElementById("childElement")
11// Get the parent element
12let parentDiv = sp2.parentNode
13
14// Insert the new element into before sp2
15parentDiv.insertBefore(sp1, sp2)
16</script>
17