DOMContentLoaded | event

Fires when a webpage has been parsed, but before all resources have been fully downloaded.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 8.2.6



Event Property object. = handler;
addEventListener Method object.addEventListener("DOMContentLoaded", handler, useCapture)


Event information



Event handler parameters

pEvtObj [in]

Type: Event

Standards information


The DOMContentLoaded event fires when the markup of a webpage has been parsed, which means it also fires before the onload event.

DOMContentLoaded is a good place to perform initialization tasks for your webpage, such as registering event handlers, initializing handles to support objects, and so on. This allows your initialization tasks to occur while the remaining resources for the webpage are being downloaded.

For more information, see the DOMContentLoaded test drive demo.


<!doctype html>
<script type="text/javascript">

function logMsg( sMsg ) { 
  var oLog = document.getElementById('ResultLog');
  oLog.innerText += "\n" + sMsg;

function addListener(obj, eventName, listener) {
	if( obj.addEventListener ) {
		obj.addEventListener( eventName, listener, false );
	} else {
		obj.attachEvent("on" + eventName, listener);

function handleDCL( e ) {
  logMsg( "DOMContentLoaded event fired.\n" ); 
   var o = document.getElementById('button1');
   addListener(o, "click", handleClick1);

function handleClick1( e ) {
  logMsg( "Button 1 clicked.\n" ); 

if(!window.addEventListener) {
	logMsg( "Can't add eventListeners; not supported." )
} else {
   addListener(document, "DOMContentLoaded", handleDCL);
   addListener(window, "load", handleLoad);


<button id="button1">Click me</button>

<p id="ResultLog">Results appear here </p>

See also