Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#8488 closed bug (fixed)

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

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 (1)

comment:1 Changed 12 years ago by dmethvin

Resolution: fixed
Status: newclosed

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.

Note: See TracTickets for help on using tickets.