closest() & matches() Playground

Click an item in your own list: Bu Guru’s board writes closest()’s ladder from e.target up to <html> and matches() on every rung. Where does closest() stop…

Why it matters

One listener on the container covers every button, including ones added later. But clicks almost always land on a child of the button (an icon, a span), so without closest() your handler misses.

The key idea

closest() climbs until it matches, and does not stop at the listener

Common mistakes

Try it in this playground