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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With