Skip to main content

Bug Tracker

Side navigation

#12692 closed bug (notabug)

Opened October 10, 2012 11:23AM UTC

Closed October 15, 2012 03:55PM UTC

Last modified October 15, 2012 03:55PM UTC

jquery toggleClass(function) behaves incorrectly

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: attributes Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:
Description

If I am correct (API documentation is not 100% conclusive)

the expected behavior of

$('div').toggleClass(function(){return (switch condition)?'yes':'no';}

should always give a DIV a class="yes" if the switch condition=true. And a class="no" if false.

However when DIV already has a class='yes' it removes the class from the div. (NB: it toggles)

See: http://jsfiddle.net/GqB8t/2/

This behavior is different from:

$().toggleClass('yes', switchcondition);

Either the documentation should be updated to reflect this behavior or it is a bug

Attachments (0)
Change History (2)

Changed October 15, 2012 03:55PM UTC by mikesherov comment:1

resolution: → notabug
status: newclosed

Thanks for contributing, but both the documentation and the code is correct in that when providing a function to toggleClass, that function shall return the class to toggle.

If you have further questions, please ask for help on the forum or in #jquery IRC on freenode.

Changed October 15, 2012 03:55PM UTC by mikesherov comment:2

component: unfiledattributes