javascript - hiding div based on unchecking checkboxes -


I have a check box in a form, based on the click of the checkbox, I show a div section. But if I uncheck a checkbox, then that division section is hidden. How do I ensure that the div section is hidden only if all checkboxes are unchecked. Crude ways may be to write my own 'display' method which will check whether all checkboxes are unchecked and then hide Div section. Any easy solution

If one or more checkboxes are checked, the following code will show div: < / P>

jQuery

version 1:

  $ ("input [name = 'mycheckboxes']"). Change (function () ($ ("$ showme"), toggle ($ ("input [name = 'mycheckboxes']: checked"). Length & gt; 0);});   

version 2 (more efficient):

  var MyCheckboxes = $ ("input [name = 'mycheckboxes']"); MyCheckboxes.change (function () {$ (" Toggle (MyCheckboxes.is (": Check");});  

HTML

  Input type = "checkbox" name = "mycheckboxes" /> input type = "checkbox" name = "mycheckboxes" /> input type = "checkbox" name = "mycheckboxes" />  

HTML

  & lt; Div id = "checkbox group" & gt; & Lt; Input type = "checkbox" name = "mycheckbox1" /> & Lt; Input type = "checkbox" name = "mycheckbox2" /> & Lt; Input type = "checkbox" name = "mycheckbox3" /> & Lt; Input type = "checkbox" name = "mycheckbox4" /> & Lt; / Div & gt; & Lt; Div id = "showme" style = "display: none" & gt; Me & lt; / Div & gt; Show  

this


Comments