I\'m trying to fix an old script written for me. I need it to run without . I\'d like to run the function from inside the script wit
Here's a slight variation on Tejs' response. I often find it more readable and manageable to separate the init() function from the code registering the event handler:
function init(e) {
//statements...
}
document.addEventListener('DOMContentLoaded', init, false);
Also, in place of an explicit init() function, I've sometimes used a self-executing anonymous function placed at the very, very bottom of the page, just before the tag:
(function() {
//statements...
})();