I have multiple checkboxes in a form. Based on clicking those checkboxes, I show a div section. But if I uncheck even one checkbox, that div section gets hidden. How do I make sure that div section is hidden only if all checkboxes are unchecked. Crude way can be to write my own ‘display’ method which will check if all checkboxes are unchecked and then hide the div section. Any easier solution??
Share
The following code will show the div if one or more checkboxes has been checked:
jQuery
Version 1:
Version 2 (more efficient):
HTML
Code in action (Version 1).
Code in action (Version 2).
— Different Checkbox Names Version —
For different named checkboxes, wrap them in a
DIVwith an identifier. E.g.jQuery
HTML
This code in action.