Programming

What is event delegation in JavaScript?

Short answer

Event delegation is a technique where you attach a single event listener to a parent element instead of separate listeners on each child, using event bubbling to detect which child was actually interacted with.

When an event happens on an element (like a click), it "bubbles up" through its ancestors in the DOM by default. Event delegation takes advantage of this, letting one listener on a parent handle events for many children.

A practical example

document.getElementById("list").addEventListener("click", function(e) {
  if (e.target.tagName === "LI") {
    console.log("Clicked item:", e.target.textContent);
  }
});

Instead of adding a click listener to every single <li> item, one listener on the parent <ul> catches clicks on any current or future list item, checking e.target to see which one was actually clicked.

Why it's useful

Last reviewed: September 2026