Update javascript-event-bubbling-capturing-delegation.md

This commit is contained in:
Angelos Chalaris
2020-09-01 01:58:29 +03:00
committed by GitHub
parent 3b6d198bd4
commit 3b0a764cf2

View File

@ -35,7 +35,7 @@ document.querySelector('.btn').addEventListener('click', e => {
});
// Bubble phase
ancestors.forEach(a => {
a.addEventListener('click', event => {
a.addEventListener('click', e => {
console.log(`Hello from ${e.currentTarget}`);
});
});
@ -73,7 +73,7 @@ Having explained event bubbling and capturing, we can now explain the three phas
Event delegation refers to the idea of delegating event listening to parent elements instead of adding event listeners directly to the event targets. Using this technique, the parent can catch and handle the bubbling events as necessary.
```js
window.addEventListener(e => {
window.addEventListener('click', e => {
if (e.target.className === 'btn') console.log('Hello there!');
});
```