Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#12692 closed bug (notabug)

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

Change History (2)

comment:1 Changed 6 years ago by mikesherov

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.

comment:2 Changed 6 years ago by mikesherov

Component: unfiledattributes
Note: See TracTickets for help on using tickets.