Skip to main content
InterviewHubPRO
Section Overview
Q92

Question 92 of 536

Part 2: Promises, Callbacks, Async & Strict Mode (54 - 103)

17%
JavaScript & V8 Internals (536 Qs)•Part 2: Promises, Callbacks, Async & Strict Mode (54 - 103)

What is event bubbling

junior LevelMost AskedCode ExampleAsync & Promises

Event bubbling is a type of event propagation in which an event first triggers on the innermost target element (the one the user interacted with), and then bubbles up through its ancestors in the DOM hierarchy — eventually reaching the outermost elements, like the document or window.

By default, event listeners in JavaScript are triggered during the bubbling phase, unless specified otherwise.

javascript
<div>
  <button class="child">Hello</button>
</div>

<script>
  const parent = document.querySelector("div");
  const child = document.querySelector(".child");

  // Bubbling phase (default)
  parent.addEventListener("click", function () {
    console.log("Parent");
  });

  child.addEventListener("click", function () {
    console.log("Child");
  });
</script>
//Child
//Parent

Here, at first, the event triggers on the child button. Thereafter it bubbles up and triggers the parent div's event handler.