Node.insertBefore()
// js
const parent = document.querySelector("#parentElement");
const insertBeforeThisElem = document.querySelector("#childElement");
const newElement = document.createElement("span")
parent.insertBefore(newElement, insertBeforeThisElem);
// file.html
<div id="parentElement">
// this exists only after running code above
// <span></span>
<span id="childElement">foo bar</span>
</div>