Syntax
addEventListener Method | object.addEventListener("DOMContentLoaded", handler, useCapture) |
---|
Standards information
- HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 8.2.6
Event information
Synchronous | No |
---|---|
Bubbles | Yes |
Cancelable | No |
Event handler parameters
-
pEvtObj
-
Type:
Event
Remarks
The
DOMContentLoaded
For more information, see the
Note
Examples
<!doctype html>
<html>
<head>
<script type="text/javascript">
function logMsg( sMsg ) {
var oLog = document.getElementByIdx_x('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.getElementByIdx_x('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);
}
</script>
</head>
<body>
<button id="button1">Click me</button>
<div>
<p id="ResultLog">Results appear here </p>
</div>
</body>
</html>
See also