Question presented to candidate: "What is event delegation, in your own words, and what specific browser mechanism makes it actually possible?"
What a strong answer should cover:
- 📌 Interview term: event delegation — a pattern that exploits event bubbling: instead of attaching a listener to every individual element you care about, you attach one listener to a shared ancestor and inspect
event.targetto determine which specific descendant triggered it. - 📌 Interview term: the enabling mechanism — event delegation is only possible because most DOM events genuinely bubble — travel from the actual target element up through each ancestor in turn, all the way to
document. Verified directly with a real dispatched event: a listener on a distant ancestor genuinely receives a click that originated on a deeply nested descendant. - A precise answer distinguishes delegation from simply "having a listener that handles multiple things" — the defining trait is that the listener is attached to an ancestor, not to the elements themselves, and relies specifically on bubbling to reach it.
- 📌 Interview term: not every event bubbles — a precise answer names that
focus/blurdo not bubble (their bubbling equivalentsfocusin/focusoutdo), which is a real, direct constraint on which events delegation can be used for at all. - A precise answer names the concrete, measured trade-off verified directly: a 1000-element collection needs exactly 1 delegated listener versus 1000 individual ones — the real reason this pattern exists, beyond convenience.
Clarifying questions expected:
- None — this is a definitional question; naming the exact underlying mechanism (bubbling) rather than just describing the observable pattern is the strong signal.
Code / implementation expected: Optional — a short delegated-listener snippet demonstrating event.target usage reinforces the definition concretely.