Favorites

DOM Document: DOMContentLoaded event

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Document: DOMContentLoaded event
DOM Document EventThis event is supported by all modern browsers.
Updated 28th November 2026

The DOMContentLoaded event fires when the HTML has been fully parsed and the DOM is ready, without waiting for images and style sheets to load.

Description

The DOMContentLoaded event fires on the document once the HTML has been completely parsed and all deferred scripts have run. It doesn't wait for images, subframes or async scripts; the window's load event does that.

It's the usual signal to start code that works with the page's elements. Scripts loaded with defer or type="module" already run after parsing, so they often don't need it. If you add the listener after the event has fired, it never runs, so check document.readyState first in code that may load late.

It's dispatched on document and bubbles to window, so you can listen on either. jQuery's $(document).ready() and similar helpers are built on this event, and like them, a check of document.readyState lets late code run immediately when the event has already happened.

Syntax

document.addEventListener('DOMContentLoaded', handler)

Example

console.log('script runs, readyState:', document.readyState);
document.addEventListener('DOMContentLoaded', () => {
  console.log('DOMContentLoaded fired');
});
window.addEventListener('load', () => console.log('load fired (after images)'));

Browser Support

The following information will show you the current browser support for the Document: DOMContentLoaded event event. Hover over a browser icon to see the version that first introduced support for this event.

This event is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee