$('.button').click(function(){
$(this).toggleClass('clicked')
$('.clicked+span').toggleClass('choice');
});
I’ve just started learning jQuery and I was playing around with some methods. So when the link with class .button is clicked, the toggleClass adds at the same time the two classes, BUT when I click it again only the .clicked is removed. The .choice class remains, despite what I thought.
Could someone explain what I’m missing here, and may be how to achieve this – toggle both classes at every click?
EDIT
Sorry, here’s the code
The thing I want to achieve is when you click ‘a)’ for example, the corresponding line gets highlighted in some way.
Ah, seeing the code make it clearer.
http://jsfiddle.net/96GZB/3/
I think you’d be better off making the span a child of the .button, so you could just set something like this in your stylesheet;
Then you can do away with the .choice class entirely.