To be clear, even bubbling and event capturing is not a react concept but a javascript & concept surrounding the behavior of the dom. To understand event bubbling, we first need to understand how the dom works.
To be clear, even bubbling and event capturing is not a react concept but a javascript & concept surrounding the behavior of the dom.
To understand event bubbling, we first need to understand how the dom works.
DOM, also known as Document Object Model, is the data representation of all the nodes and contents of the web application.
This probably doesn’t make a lot of sense unless you are a developer so allow me to be even more bare bone about this:
Here is a better picture of how it can look like:
Let’s say we the div and the p are attached with onClick functions themselves, with the div’s onclick function printing out “console.log(“this is div”)” and the p’s onclick function printing out “console.log(“this is p”)”.
With event bubbling, when the user clicks on p it will bubble down to p, trigger the onclick function there, the trigger div’s onclick function and another onclick function that its parents and/or grandparent nodes contain.
The workflow will be as following: p->div-> body-> html
Here is an example of how it will work in a react application:
Bubbling in real life is when a bubble goes from the bottom of the glass to the top of it. When you put the soda into the glass, you see bubbles go from the bottom to the top. But in the JavaScript Programming language, Event Bubbling happens when you have an event on an element of a web page.
HTML Assignment Help Australia @30% OFF from Sample Assignment, with Our Best HTML assignment help experts. Get HTML homework help online at affordable price. 100% Plag free assignment solution.
Learn HTML and javascript, their uses & importance, html javascript function, javascript tags list, why add javascript file to html, HTML Events with JavaScript etc
What is Event Propagation in JavaScript ? Event Bubbling and Event Capturing in JavaScript? Event bubbling and capturing are two ways of event propagation in the HTML DOM API,
JavaScript events are the catalysts behind most web functionality. Interacting with literally any website means firing away a ton of events.