Typically, JavaScript execution is delayed until the entire document is loaded using an event window.onload.
window.onload = function() {
};
Otherwise, if you do not want this or you do not need to wait for the entire document to load, you can enable your JavaScript immediately after the closing element ( div) tag that interests you.
<div>
...
</div>
<script src="blah-blah-blah.js"></script>
source
share