Episode 21 game · Raiden · Lightning

Raiden’s Relay

Kai gave every ✕ button its own click listener when the page loaded. Rows he adds later stay deaf. Feel the dead button, fix it with one listener on the list and closest(), then prove a single listener handles every row, old or new.

RaidenA click is lightning, Kai. It climbs. Add a row to your list and click its ✕.
21Seal 21
kai.app/todo
ul#list

    Clicks will show up here.

    Who is listening getEventListeners() in DevTools
    • click listeners on ✕ buttons0
    • click listeners on ul#list0
    • deaf ✕ buttons0
    
        

    1 · Feel the deaf button

    Three rows were there when the page loaded, and each ✕ got a listener. Add a row the way Kai does, then click the new row’s ✕.

    A snapshot, not a subscription

    querySelectorAll() returns a static list. Listeners added from it never reach elements added later.

    Clicks bubble

    A click on a button travels up through the li and the ul. One listener on the list hears every row.

    Ask closest()

    event.target.closest('.delete') finds the button even when the click lands on its icon. focus doesn’t bubble: delegate focusin.