From 3b0a764cf222e6afa24648385a026da984a41f94 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 1 Sep 2020 01:58:29 +0300 Subject: [PATCH] Update javascript-event-bubbling-capturing-delegation.md --- blog_posts/javascript-event-bubbling-capturing-delegation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blog_posts/javascript-event-bubbling-capturing-delegation.md b/blog_posts/javascript-event-bubbling-capturing-delegation.md index 7a55c5c06..928d3bb30 100644 --- a/blog_posts/javascript-event-bubbling-capturing-delegation.md +++ b/blog_posts/javascript-event-bubbling-capturing-delegation.md @@ -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!'); }); ```