Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMarko Vojvodic
32,207 PointsProblem with button responding on second question?
Hi guys i have a problem with button responding, when second question occure. I've tried to solve this problem but i couldn't find answer. I've coded different.
Here is my work https://w.trhou.se/5qor4wwnpu
1 Answer
Steven Parker
231,269 PointsYour new buttons don't have event listeners.
In app.js, after you call quiz.renderIn which creates the button elements, you attach event listeners to each button. But when the buttons are clicked, the original button elements are replaced with new ones in another call to quiz.renderIn. The newly-created buttons never get event listeners, so clicking on them doesn't cause any action.
I can think of 3 ways to resolve this issue offhand:
- attach new event listeners each time the buttons are re-created
- don't remove and replace the buttons when the question changes, so the original handlers still work
- use a delegated event handler that will operate with both current buttons and those created later
Marko Vojvodic
32,207 PointsThank a lot, i've just solve the problem attaching new event listener
Marko Vojvodic
32,207 PointsMarko Vojvodic
32,207 PointsSorry, just edited link :)