Select with `querySelector`, update with `textContent` (safe) rather than `innerHTML` (an XSS risk with untrusted data). Event delegation attaches one listener to a parent and inspects `event.target`.
list.addEventListener("click", (e) => {
const btn = e.target.closest("button[data-id]");
if (btn) select(btn.dataset.id);
});Remove listeners you add to `window` or `document` when a component unmounts.