At the moment the script is enabled, he is sure that the last one <script>on the page will be current; the rest of the page has not yet been parsed. So:
<script type="text/javascript">
var scripts= document.getElementsByTagName('script');
var this_script= scripts[scripts.length-1];
setTimeout(function() {
var div= document.createElement('div');
div.appendChild(document.createTextNode('Hello!'));
this_script.parentNode.insertBefore(div, this_script);
}, 5000);
</script>
This is done if the script tag is not using deferor HTML5 async.
source
share