[Solved] position of a script tag is influencing the code execution [duplicate]
Scripts should always be loaded at last and at the bottom of the body so they can access the DOM and the elements. You can wrap this around your code, so it is executed when eversthing is loaded document.addEventListener(“DOMContentLoaded”, function() { // your code }); or document.attachEvent(“onreadystatechange”, function(){ if (document.readyState === “complete”){ document.detachEvent( “onreadystatechange”, arguments.callee … Read more