// bubbling happens from the innermost, outward. they occur after the capturing phase
document.querySelector('#outer1').addEventListener('click', function() {
console.log('bubble div outer1 hit');
}, false);
document.querySelector('#outer2').addEventListener('click', function() {
console.log('bubble div outer2 hit');
}, false);
document.querySelector('#outer3').addEventListener('click', function() {
console.log('bubble div outer3 hit');
}, false);
// capturing happens first, and starts from outermost, inward
document.querySelector('#outer1').addEventListener('click', function() {
console.log('capture div outer1 hit');
}, true);
document.querySelector('#outer2').addEventListener('click', function() {
console.log('capture div outer2 hit');
}, true);
document.querySelector('#outer3').addEventListener('click', function() {
console.log('capture div outer3 hit');
}, true);
// When added to the same element, they get run in the order they were added, regardless of the event handling type
document.querySelector('#link').addEventListener('click', function() {
console.log('link capture');
}, true);
document.querySelector('#link').addEventListener('click', function() {
console.log('link non-capture');
}, false);
// Try adding some `.preventDefault` calls in the code to see what impact they have on the logging messaging!
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.