Run code when the document has loaded.

Most popular JavaScript frameworks make it easy to run code when the document is loaded. But if you aren't using a framework, you can simply listen for the DOMContentLoaded event instead.

This event is fired when the document's HTML is loaded and parsed, but before any stylesheets or images may be loaded.

document.addEventListener("DOMContentLoaded", init, false);

function init() {
     console.log("init");

 }
comments powered by Disqus