how to use insertbefore in javascript code example
Example 1: js insertbefore
let insertedNode = parentNode.insertBefore(newNode, referenceNode)
Example 2: javascript insertBefore
<div id="parentElement">
<span id="childElement">foo bar</span>
</div>
<script>
let sp1 = document.createElement("span")
let sp2 = document.getElementById("childElement")
let parentDiv = sp2.parentNode
parentDiv.insertBefore(sp1, sp2)
</script>
Example 3: javascript add element above
$( "<p>Test</p>" ).insertBefore( ".inner" );