Help with jQuery .toggleclass


(Oliver Kass) #1

Hi folks,

 

My knowledge of java / jQuery is letting me down and I'm struggling to get .toggleclass to work on the following code:

 

http://jsfiddle.net/qMNVr/

 

I've got the slidetoggle script working but want to figure out how to toggle the colour of the > when it's clicked on. e.g. it will turn to blue when the div is revealed.

 

And..the iceing on the cake would be to get the > to point down the way on click :)

 

As always any help would be much appreciated.

 

Oli


(Nic Hubbard) #2

I have updated it for you: http://jsfiddle.net/qMNVr/8/

 

There are much better ways to do it. Currently you are using 5 click events which shouldn't be needed. But at least it works now how you wanted. :)


(Cgrist) #3

There's actually a built in jquery toggleClass function, so you should just be able to use something like $(this).toggleClass('red')


(Benjamin Pearson) #4

I have updated it for you: http://jsfiddle.net/qMNVr/8/

 

There are much better ways to do it. Currently you are using 5 click events which shouldn't be needed. But at least it works now how you wanted. :)

Expanding on what Nic said... http://jsfiddle.net/xCg33/


(Oliver Kass) #5

Thanks for all your help guys. I had a feeling that there would be a way of boiling the code down a bit.

 

Oli