I have an application where data sets can be filtered at various levels, and--for performance reasons--it would be nice to be able to toggle the respective display of nested divs independently. The issue arises in that toggle will change the display property back to its original state on a hidden child, but it will not change it to none if one of its ancestors is already hidden.
To replicate: in this JSFiddle,
toggle can take a boolean
$(selector).toggle(false);
http://api.jquery.com/toggle/
.toggle( showOrHide )
showOrHideA Boolean indicating whether to show or hide the elements.
UPDATE
You can achieve the functionality you want by creating a simple hidden
css class calling toggleClass()
rather than using toggle()
. toggle()
seems to skip its own functionality entirely if the element in question is not visible.
http://jsfiddle.net/hunter/GufAW/3/
$("#toggle-1").click(function() {
$("#1").toggleClass("hidden");
});
$("#toggle-2").click(function() {
$("#2").toggleClass("hidden");
});
$("#toggle-3").click(function() {
$("#3").toggleClass("hidden");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With