How do event bubbling and delegation help with a dynamic list of buttons?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
Many events propagate from the target through ancestor elements. Delegation attaches a listener to a stable ancestor and identifies the relevant descendant, avoiding one listener per dynamically created button. Use closest to handle clicks on icons inside a button, verify that the matched element belongs to the intended container, and choose the right event because not every event bubbles. Keep keyboard behavior accessible through native controls. Avoid indiscriminate stopPropagation calls because they can break other listeners and obscure the event flow.
Related Questions in JavaScript & Web Technologies
Explain the JavaScript Event Loop, Call Stack, Microtask, and Macrotask Queues
Intermediate level • 429 views
How do let, const, and var differ in scope and reassignment?
Easy level • 7 views
What is the output of synchronous code, a resolved promise, and setTimeout with zero delay?
Medium level • 7 views
How should fetch code handle HTTP errors and malformed JSON?
Medium level • 7 views
What is a closure? Show a practical example.
Easy level • 6 views