Bug Tracker

Modify

Ticket #8488 (closed bug: fixed)

Opened 2 years ago

Last modified 14 months ago

.toggle( showOrHide ) is not consistent with documentation

Reported by: kellyselden Owned by:
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.5.1
Keywords: Cc:
Blocking: Blocked by:

Description

the documentation says it is the equivalent to

if (showOrHide) {
  $('#foo').show();
} else {
  $('#foo').hide();
}

but if showOrHide = 1, toggle will not show it because it is checking for a boolean type at line 7498 in jquery 1.5.1

toggle: function( fn, fn2, callback ) {
    var bool = typeof fn === "boolean";

my simplified code looks something like this when i ran into the problem:

function toggleSection(show) {
    //bunch of stuff based on show
    $('.something1').toggle(show);
}

toggleSection($('.something2:checked').length);

my work-around is to always remember to check against true

$('.something1').toggle(show == true);

Change History

comment:1 Changed 2 years ago by dmethvin

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

I've updated the docs to clarify the equivalent code to emphasize that it needs a Boolean argument or it won't match that particular API signature.

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.