Skip to main content

Bug Tracker

Side navigation

#10777 closed bug (invalid)

Opened November 13, 2011 02:40PM UTC

Closed November 13, 2011 02:55PM UTC

.toggleClass( className, switch ) works incorectly with non-bool type 'switch' argument

Reported by: San4es Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7
Keywords: Cc:
Blocked by: Blocking:
Description

When you use non-bool "switch" argument .toggleClass works incorrectly in some cases:

.toggleClass(className, true) != .toggleClass(className, 1)

.toggleClass(className, 0) != .toggleClass(className, false)

I consider that this function should work as stated in the documentation, as

if (addOrRemove) {
    $('#foo').addClass(className);
else
    $('#foo').removeClass(className);

I tests all version of jquery.

Examples here: http://jsfiddle.net/f2NU3/

Attachments (0)
Change History (1)

Changed November 13, 2011 02:55PM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

Quote from the documentation,

A Boolean (not just truthy/falsy) value to determine whether the class should be added or removed. -- http://api.jquery.com/toggleClass/

There is a jQuery UI extension that accepts a number as its second parameter.

http://jqueryui.com/demos/toggleClass/