I'm confused with the script below:
var event = new Event('shazam');
document.body.addEventListener('shazam',function(){
alert('body');
});
document.addEventListener('shazam',function(){
alert('document');
});
window.addEventListener('shazam',function(){
alert('window');
});
document.body.dispatchEvent(event);
When I run this script on my browser, I just get the alert('body'); event. but if i set the capturing parameter of addEventListener (the third optional parameter) to true, all the alerts captured in order they should.
Why the shazam event doesn't bubble up ?
CustomEvent
instead ofEvent
and pass ittrue
as the second parameter (the canBubble parameter) – Determined