A client is using Sharetribe which allows you add custom JS via admin, but only in the head. I want my script to load after jQuery, but jQuery is loaded at the end of the body. How can I write vanilla JS that adds my main script to the end once the doc loads?
I tried this:
<script>
var script = document.createElement(script);
script.type = text/javascript;
script.src = http://cdn...;
document.body.appendChild(script);
var script2 = document.createElement(script);
script2.type = text/javascript;
script2.text = $(SOME.CODE.HERE);
document.body.appendChild(script2);
</script>
But it gets executed before the document is finished loading (and in particular, before jQuery is available). The only thing I can think of is to set a timer, but that seems buggy.
Any advice?