Search code examples
jquerytoggleclass

Anyone else ever has this issue with jquery toggleClass?


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


Solution

  • 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