The pantry starts with Rice. The supplied Add item button builds a Beans row, but neither row's Remove button has a handler yet.
First complete the supplied removePantryItem(event) function. It receives a clicked target and the list as currentTarget. Use closest("button[data-remove]") to handle clicks on nested labels, then check containment before removing the button's closest li. An early return leaves unrelated clicks alone.
Next register that function on the pantry list. The supplied window.removePantryItem reference is only for calling the helper independently; it does not register a listener.
removePantryItem(event) to remove the matching button's row only when the button is inside event.currentTarget. Ignore ordinary row clicks and buttons outside that list.#pantry, so existing and later-added buttons work through the same listener.Edit script.js, then Run. Step 1 alone does not make the buttons work, but Submit can check the handler directly. After step 2, remove Rice, add Beans, and remove Beans by clicking its nested label. Clicking plain row text must still do nothing.
Inside the listener, use event.target.closest("button[data-remove]") and verify the button belongs to event.currentTarget.