javascript - jQuery dynamically mark all checkboxes checked -
i have following html structure -
<div class="first_checkbox"> <input type="checkbox" name="checkbox" class="all-checkbox" value=""> </div> <table> <tr> <td> <input type="checkbox" name="checkbox-32" id="checkbox-32" value="" style="opacity: 0;" /> </td> <td class="h_pincode">380059</td> <td class="b_add2">nr. swatik cross road, navrangpura</td> </tr> <tr> <td> <input type="checkbox" name="checkbox-34" id="checkbox-34" value="" style="opacity: 0;" /> </td> <td class="h_pincode">380015</td> </tr> </table>
the functionality, want achieve is, when click on first radio box, subsequent checkbox in s checked.
the js follows -
$(function(){ $(".all-checkbox").on("click", function(){ $('input[type=checkbox]').each(function(ind, val){ $(this).prop('checked', 'checked'); console.log(this.name + ' ' + this.value + ' ' + this.checked); }); }); });
i getting console logs correctly, difference being, radio boxes not checked.
the fiddle located here - http://jsfiddle.net/dajm8/
check jsfiddle
jquery
$("#checkbox-all").click(function () { $('input:checkbox').not(this).prop('checked', this.checked); });
Comments
Post a Comment