I had a functionality of multiple checkbox..in which if we check multiple childs need to be checked and vice versa. BUt it is only happening on the third click. if we click the allcheck all childs are checked and vice versa.. but the functionality i need is if even one child is checked and if we click allcheck remaining need to be checked..and if we uncheck even one child allcheck needs to be unchecked.I used this code
html:
<li class="inputradio"><input name="allCheck" type="checkbox" ></li>
<li id="childcheckbox"><input name="childCheck" type="checkbox"></li>
all check
<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>
<!--<li class="deletebutton"><a href="#" class="bt btleft">Delete</a></li>
<li class="copy"><a href="#" class="bt btright">Copy</a></li>-->
<li class="shatebutton"><a href="#" class="bt stmiddle">Share</a>
<div id="smenu">
</div>
child:
<div id="rightoutputimgae">
<div id="rightimgId" class="rightimg" rel="tooltip"
content="<img src='jqe13/image/1.jpg' class='tooltip-image'/> ">
<div id="outputimageId" class="outputimage">
<img src="jqe13/image/1.jpg" alt="Right Bottom Image"></div>
</div>
<ul><li id="childcheckbox"><input name="childCheck" type="checkbox"></li>
<li id="outedit"><a href="#"><img src="jqe13/image/edit_s.PNG" alt="edit" title="Edit">
</a></li>
<li id="outdelete">
<a href="#" onclick="deleteImg()">
<img src="jqe13/image/delet_c.PNG" alt="delete" title="Delete"></a></li>
<li id="outfullscreen">
<a href="#"><img src="jqe13/image/fullscreen_c.PNG" alt="Full Screen"
class="fullscreen" title="Full Screen"></a></li>
jquery:
$('.inputradio').click(function () {
$('input[name=allCheck]').click(function () {
$("input[name='childCheck']").prop('checked', this.checked);
});
$("input[name='childCheck']").click(function () {
if ($('input[name=childCheck]:checked').length === $('input[name=childCheck]').length) $('input[name=allCheck]').prop("checked", true);
else $('input[name=allCheck]').prop("checked", false);
});
});
can anyone tell me what is wrong in this
.inputradiois clicked you'll add additional click handlers to the inputs.[]should be in quotes after the equals sign.[name=childCheck]should bename="childCheck"]