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
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
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
- Related events:
load
,readystatechange
,beforeunload
,unload
- This event on
Document
targets:DOMContentLoaded