add/remove class on click? [SOLVED]
Hi,
I've used the following code to add/remove class on hover:
$('#hover-demo2 p').hover(function() {
$(this).addClass('hover');
}, function() {
$(this).removeClass('hover');
});
I even manage to add a class on click using the above code, but ca't remove the same class.
I want to be able to remove the class by clicking the same element, or if possible, clicking any another element.
For example:
Click on x adds a class to it, and click on y or z (not 'just' y or z) removes the class from x and adds another to whichever is clicked, y or z.
Is it possible? I would appreciate any help.
Many thanks.