This problem is paper-only - see explanation for the canonical JS solution.
Instead of attaching N click handlers to N buttons, attach one to a common ancestor and use event.target.closest(selector) to identify the actual clicked element. The auto-grader validates the closest() walk.
Given a flat parent->child tree ({ id, parentId | null, classes: string[] } rows) and a starting node id, walk up via parent links and return the first ancestor (or self) whose classes contain the target class, or null if none.
For the auto-grader: implement findAncestor(nodes, startId, targetClass). Return the matching node id, or null.