Skip to main content
InterviewHubPRO
Section Overview
Q114

Question 114 of 536

Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

21%
JavaScript & V8 Internals (536 Qs)•Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

What is an event delegation

junior LevelCode ExampleHTTP & REST APIs

Event delegation is a technique where you attach one event listener to a parent element instead of adding listeners to each child element. It works because events bubble up from the target element to its parents.

For example, if you wanted to detect field changes inside a specific form, you can use event delegation technique,

javascript
  var form = document.querySelector("#registration-form");

  // Listen for changes to fields inside the form
  form.addEventListener(
    "input",
    function (event) {
      // Log the field that was changed
      console.log(event.target);
    },
    false
  );