javascript onDOMContentLoaded doesn't trigger

html, javascript

Solution

You should be binding to the event with `addEventListener`:

document.addEventListener("DOMContentLoaded", function() {
    alert('aaaaaaaaaaaaaa');
});

http://jsfiddle.net/qHa4T/1

Keep in mind that both `addEventListener` and `DOMContentLoaded` won't work with IE8 and below.

Problem

Any ideas why this code doesn't work? ``` <html><head> <script type="text/javascript"> document.onDOMContentLoaded=function(){ alert('aaaaaaaaaaaaaa'); } </script> </head> <body> <div id="mydiv"></div> </body> </html> ``` onDOMContentLoaded is expected to triogger when the webpage is loaded and make that alert but it doesn't work dunno why

Original source