Forgive me for being a noob, but shouldn't this work?
$(document).ready(function() {
$('.button').click(function() {
$(this).addClass('button-clicked');
});
$('.button-clicked').click(function() {
$(this).removeClass('button-clicked');
});
});
Shouldn't the second click remove the class and take it back to .button?
Here it is on jsfiddle: http://jsfiddle.net/pXdwM/
no, because at the point you're calling the second click()
the button doesn't have ".button-clicked" and therefore event handler is not assigned. You could rewrite it like this
$('.button').click(function() {
$(this).toggleClass('button-clicked');
});
or use live()
$('.button-clicked').live("click", function() {
$(this).removeClass('button-clicked');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With