DOM Document: DOMContentLoaded event
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
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.
Desktop





Tablets & Mobile





