For further actions, you may consider blocking this person and/or reporting abuse
Read next
Indisputable Proof That You Need Drip Coffeee
Dupont Branch -
🚀 5 Browser Extensions That Will Boost Your Development
Yanaiara Oliveira -
Crafting a Scalable Node.js API: Insights from My RealWorld Project with Express, Knex, and AWS CDK
Ken Yip -
Upgrade do MongoDB - o guia definitivo.
Paulo Benjamin -
Top comments (2)
Bubbling happens when an event is actually fired on an element, it will first handle the event on itself, then the event on it's parent(if any) and continue till it reaches the body and the root element.
Imagine you have a P tag inside a DIV tag which is inside the BODY tag, and all three of them have a "click" event listener. Now you click on the P. The event on P will fire first, followed by the event on DIV, followed by the event on BODY.
This is just like the bubbles which rise from the bottom to the top in a carbonated drink, hence the name bubbling.
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.