Reputation: 3126
I'm trying to create simple function that will work two ways. Basically, when I click on .slideme
once it will add a class, and when I click second time it will remove that class.
I have this:
$(".slideme").click(function() {
$('#login').addClass("green");
},function(){
$('#login').removeClass("green");
});
Unfortunately it works only half way; when I click the second time nothing happens.
How can I solve this please?
Upvotes: 0
Views: 226
Reputation: 344507
Just use toggleClass:
$(".slideme").click(function() {
$('#login').toggleClass("green");
});
Working example: http://jsfiddle.net/AndyE/ZQfeW/
Upvotes: 4