Event Delegation

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Event Delegation

Approach

Register a single event handler on a parent element rather than individual handlers on each child. The handler inspects the event target's attributes (such as action and id) to determine which child was clicked and responds accordingly.

Complexity Analysis

Time
O(1) per event
Space
O(1)

Pattern

Event Delegation

Why It Works

DOM events bubble up from child to parent, so a single parent handler can intercept all child events. This reduces memory usage and automatically handles dynamically added children.

Updated Feb 2026