Solution Review: Destroy the Button
This lesson will explain the solution to the problem in the previous lesson.
We'll cover the following...
Solution #
Explanation #
The first approach that comes to mind is to attach an event listener to the button
; it can destroy itself when clicked and create two new buttons in its place. However, this is not an efficient approach since you’ll have to add the event handler to each button created.
A smart way to solve this problem is to make use of event delegation. We attach the event handler to the parent div
instead of each button. In our solution, we are attaching the event handler for the ...