Closed lmdragun closed 9 years ago
Do you get an error? And have you console.log
-ed through your script to see where it starts to break?
Nope, no errors, nothing javascript-y happening at all when I click. I looked in the chrome console and the class IS appearing when the button appears.
Ah, I see now. Event listeners set on page load only work on the elements that were created when the page was loaded. So if you have this:
$(document).ready(function(){
$(".blah").click(function(){
console.log("Hello");
});
});
...it won't work on any new .blah
you create. You'll have to re-attach the event listener.
How would I re-attach? just have it within the function that creates the new button?
Try it!
I have an event listener at the very beginning of my game, on the start button. I wanted to have a restart button after the game is over where the players can just click that instead of refreshing. I'm making it with javascript and for some reason the event listener isn't catching it.
(#start is the 'modal' like popup I have at the beginning and end of the game)
my gameOver function:
my event listener:
I also tried just using the "start" listener over again, which works initially but doesn't work for this new one.