Modify ↓
Ticket #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: | ||
| 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
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
Note: See
TracTickets for help on using
tickets.

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.