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,
- Click the “toggle 3” button, and then the “toggle 2” button.
- Clicking the “toggle 3” button and then the “toggle 2”, you will find 3 restored (as expected).
- Now click the “toggle 2” button, then the “toggle 3”.
- On clicking “toggle 2” again, 3 is still visible (???).
toggle can take a boolean
http://api.jquery.com/toggle/
UPDATE
You can achieve the functionality you want by creating a simple
hiddencss class callingtoggleClass()rather than usingtoggle().toggle()seems to skip its own functionality entirely if the element in question is not visible.http://jsfiddle.net/hunter/GufAW/3/