How Event bubbling & Event capturing works

How Event bubbling & Event capturing 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.

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:

  • The DOM is what allows you to see all the stuff on this web browser and it manages it.

Here is a better picture of how it can look like:

Image for post

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:

javascript event-bubbling html

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

What is Event Bubbling and Event Capturing in JavaScript?

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.

Know Everything About HTML With HTML Experts

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.

HTML JavaScript - Add Javascript File to HTML

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? Event Bubbling in JavaScript?

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,

The Art of JavaScript Event Delegation

JavaScript events are the catalysts behind most web functionality. Interacting with literally any website means firing away a ton of events.