Coding task · JavaScript and TypeScript course · Module 8: Events and the DOM

Exercise: Event Delegation

Apply event delegation to handle clicks on the dinosaur list.

Task

The index.html file has a list of dinosaur cards #dino-list and a button that adds a new card after the page has loaded. Use event delegation: replace ___BLANK1___ with the variable of the container that holds the only click listener, and ___BLANK2___ with the method that starts at event.target and looks for the closest element matching the .dino-card selector. Clicking a card (also its inside and a card added later) should show the dinosaur name in #selected-dino, while the reserve card outside the list should not react.