javascript - check child check box by parent check box in jquery -


i trying check child check box parent check box in jquery. code work first time next stop working

$(document).ready(function () {     $("#append").delegate("#p0", "click", function () {         if (this.checked == true) {             $("#submenu0 input").attr('checked', true);         } else {             $("#submenu0 input").attr('checked', false);         }     }); 

html

<div id="append" name="append" style="background-color: white;">     <input type="checkbox" id="p0" value="administrative boundary">     <div id="submenu0" class="a" style=" margin-left: 29px ">         <input type="checkbox" id="pc00" value="kbjnl:district_boundary_2011" checked="checked">district boundary 2011         <br>     </div> </div> 

you can use checked status of clicked checkbox, update other checkboxes.

see comments inline.

// use change event, , on bind events, delegate calls on inside $("#append").on("change", "#p0", function() {     $("#submenu0 :checkbox").prop('checked', $(this).is(':checked'));     // if checkbox checked check checkboxes inside #submenu0 }); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -