var ref = document.getElementsByTagName('script')[0]; ref.parentNode.insertBefore(yourElem, ref); But you prefer a good old document.body.appendChild(elem); Awww! I know, man. I used to, too. Well, you can’t always trust this.. Especially if you’re writing library, widget or third-party code. Here’s why you can trust this insertBefore method, and why all the other techniques are not wise: appendCh