DOCUMENT

Events

The JavaScript Document Events. Various examples and resources.

DOMContentLoaded

Checking whether loading is already complete

function doSomething() {
  console.info('DOM loaded');
}

if (document.readyState === 'loading') {  // Loading hasn't finished yet
  document.addEventListener('DOMContentLoaded', doSomething);
} else {  // `DOMContentLoaded` has already fired
  doSomething();
}
comments powered by Disqus