Skip to content
Advertisement

Why do I have to click twice for this JavaScript function to work?

In order for the fucntion to change the display to “hidden” then back to “block” it requires 2 clicks for each. Why is this? How do I reduce it to just one click?

JavaScript
JavaScript

Advertisement

Answer

That’s because you’re registering an event listener on every click! So your listener executes once more every time you click.

Your code fixed:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement