DEV Community

Discussion on: Explain Event Bubbling and event delegation like water

Collapse
 
tusharkashyap63 profile image
Tushar Kashyap

Event delegation is a technique by which you can add an event listener on a parent element and perform that event on it's child element. This is necessary to understand because you may not have access to the element currently(maybe it is created after an API call return) so you can set the event handler on it's parent which you have created yourself.
Another usecase is that it can save you alot of time if you have numerous same type of elements and you want all of them to have the same event, you can set the event handler on it's parent and use the event.target property to know on which child element the event happened and use it accordingly.