Last active
August 29, 2015 14:10
-
-
Save sfasano/82a3701b70e86478cc19 to your computer and use it in GitHub Desktop.
I'm having an issue with reassigning the Button to .second
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This took me a few minutes to sort out but I think I got it :)
On line 24, you're adding the class of
.second
to your button, but by the time it finishes adding that class, it's already finished running line 27—right away. So basically, line 27 runs only once, and when it runs, nothing on the page has the.second
class yet, so it's never called, and your code moves on.To rephrase another way:
When your document loads, all your code runs, and everything that doesn't require an input happens right away. That includes line 27, except then (at the beginning) nothing has a class of
.second
yet, so it doesn't do anything. Some time later, you click on.first
and it gets replaced with the new class.second
but nothing tells line 27 to then run again, so nothing happens this time either :pSo the solution looks something like this:
$(document).on("click", ".second", function() { ... })
—which says "also when people click, check for.second
and if you find THAT, do this other thing".So basically you'd have code then that on every click checked for
.first
, and more code that checked for.second
and each has a different outcome.Make sense?