Reputation: 75
I have some problem right now with this: http://jsfiddle.net/jalxob/WkWyc/1/
$(".show_hide").addClass( "hola1" );
The "show" link is in green and when I click on it to show the div it turns yellow, but when I click it again to hide the div the "show" link stills in yellow.
Is there any way to turn it as green (the default class)?
Thank you so much!
Upvotes: 0
Views: 63
Reputation: 674
Instead of doing addClass("hola2") on your click. Do toggleClass("hola2").
This will remove the class if it is there or add the class if not.
Upvotes: 0
Reputation: 68586
You'd use jQuery's toggleClass()
method instead of addClass()
to achieve this.
$(".show_hide").toggleClass("hola2");
Upvotes: 4