DOM Enlightenment Book
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<div>click me to start event flow</div>
<h4 style="border-top:1px solid #ADADAD;padding-top:20px;margin-top:20px;"><strong>← Code Example from <a href="http://www.domenlightenment.com/" target="_blank">DOM Enlightenment Book</a> by <a href="http://www.codylindley.com" target="_blank">Cody Lindley</a></strong></h4>
<p style="background-color:#fff">JavaScript code is executed on page load. Click the "Run" button in the top bar to re-run the JavaScript code. All <code>console.log()'s</code> are logged to the <a href="http://getfirebug.com/firebuglite" target="_blank">Firebug Lite</a> console below
↓.</p>
JavaScript
//1 target phase occurs during bubbling phase
document.querySelector('div').addEventListener('click', function() {
console.log(1);
}, false);
//2 bubbling phase
document.body.addEventListener('click', function() {
console.log(2);
}, false);
//3 bubbling phase
document.documentElement.addEventListener('click', function() {
console.log(3);
}, false);
//4 bubbling phase
document.addEventListener('click', function() {
console.log(4);
}, false);
//5 bubbling phase
window.addEventListener('click', function() {
console.log(5)
}, false);