Bug Tracker

Modify

Ticket #10777 (closed bug: invalid)

Opened 19 months ago

Last modified 19 months ago

.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:
Blocking: Blocked by:

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/

Change History

comment:1 Changed 19 months ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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/

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.