3

I have a div that i'm toggling a class on click it starts off with a gold class

if i call toggelClass like so

$('#HomePageFavourite').toggleClass('gold grey');

what i'm left with is a div with both gold and grey classes (i would have expected the gold to have been stripped out since it's already been applied) so that if i click again, grey should get removed and gold applies again

it works when i do this

$('#HomePageFavourite').toggleClass('gold');
$('#HomePageFavourite').toggleClass('grey');

but that defeats the purpose

not sure why this is happening

topwik
  • 3,487
  • 8
  • 41
  • 65
  • It seems to work for me: http://jsfiddle.net/fkling/nsvCD/ Maybe you are adding the class somewhere again. Obviously the method works by itself. If you want help, please add more code and better, create a http://jsfiddle.net/ demo. – Felix Kling Aug 17 '11 at 20:03
  • What you have works for me in Chrome: http://jsfiddle.net/mrchief/2ZsD4/ – Mrchief Aug 17 '11 at 20:03
  • if i run this in the firefox console, it's not doing what I expect $('#HomePageFavourite').toggleClass('gold grey'); if i start with just grey and run that repeatedly, i end up with both classes on there. it;s not removing if it's already there for some reason. – topwik Aug 17 '11 at 20:11
  • the order i pass the classes into the function shouldn't matter should it? i wouldn't think so... – topwik Aug 17 '11 at 20:13
  • same behaviour in chrome i'm seeing as in fifo. seems odd. i start with one class, gold. i then run toggleClass('gold grey') on the div and the div gets both classes... – topwik Aug 17 '11 at 20:15

1 Answers1

0

ok it was a jquery version issue/side-effect. the page i was working on was using an older version of jquery; 1.2.6 or something. i updated to 1.6.2 and it's working as expected

cheers folks

topwik
  • 3,487
  • 8
  • 41
  • 65