Web/API/Window/DOMContentLoaded event

From Get docs


The DOMContentLoaded event fires when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.

Bubbles Yes
Cancelable Yes (although specified as a simple event that isn't cancelable)
Interface Event
Event handler property None

The original target for this event is the Document that has loaded. You can listen for this event on the Window interface to handle it in the capture or bubbling phases. For full details on this event please see the page on the Document: DOMContentLoaded event.

A different event, load, should be used only to detect a fully-loaded page. It is a common mistake to use load where DOMContentLoaded would be more appropriate.

Examples

Basic usage

window.addEventListener('DOMContentLoaded', (event) => {
    console.log('DOM fully loaded and parsed');
});

Specifications

Specification Status
HTML Living Standard Living Standard

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
DOMContentLoaded event Chrome

Full support 1

Edge

Full support 12

Firefox

Full support 1

IE

Full support 9

Opera

Full support 9

Safari

Full support 3.1

WebView Android

Full support 1

Chrome Android

Full support 18

Firefox Android

Full support 4

Opera Android

Full support 10.1

Safari iOS

Full support 2

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support


See also