
Insert an element before another one. Call the before()
method on the reference node, and pass in the new node as an argument.
// Create a new element
var newNode = document.createElement('div');
// Get the reference node
var referenceNode = document.querySelector('#some-element');
// Insert the new node before the reference node
referenceNode.before(newNode);
Source
https://vanillajstoolkit.com/reference/dom-injection/element-before/