Skip to content
Onsite

Write a delegated event helper: on(root, selector, type, handler).

MediumP2Coding

Write an event delegation helper:

const off = on(root, selector, type, handler);

It adds one listener to root for events of type. When an event comes from inside an element matching selector (the target itself or a descendant of it), call handler with the event and the matched element. It returns a function that removes the listener.

Build a small demo page around it: a list whose items are added and removed at run time, with a click counter that proves new items work without re-attaching anything.

Time box: 30 to 40 minutes.

Requirements

0 / 7

Stretch goals

0 / 3

Only after every requirement works.

Hints

Workspace

Your files are saved in this browser as you type.

When every requirement works, mark it complete to count it as solved.

Solution notes

How a strong candidate structures it, and what interviewers check.

Saved automatically