javascript - all checkboxes need to be checked and unchecked with the main checkbox -
can me this?
i have 2 divs. in 1 div, have checkbox named allcheck, , in other other div, have checkboxes name outcheck. if check multiple, need checked, , if uncheck multiple, should unchecked. input radio class of allcheck.
$('.inputradio').click(function(){ $("input[name='outcheck']").each(function () { if (allcheck.checkbox== true) {//multi check checked this.checked = true; } else { this.checked = false; } }); }); html
this div main checkbox
<div id="actions"><div id="box"> <ul><li class="inputradio"><input name="allcheck" type="checkbox" ></li> <li class="multiple"><a href="#" class="bt btleft">multiple</a></li> this child checkboxes:
<ul><li id="outcheckbox"><input name="outcheck" type="checkbox"></li> even if 1 child checked, if check main checkbox, need selected. code posted inverting check.
try -
$('input[name=allcheck]').click(function(){ $("input[name='outcheck']").prop('checked', this.checked); }); this toggle checkboxes having name outcheck on click of allcheck.
see demo
update
see updated demo here
this works expected. if checkboxes manually checked main checkbox changes , vice versa if 1 child unchecked, main checkbox gets unchecked.
Comments
Post a Comment