Here’s a short snippet to have check/uncheck to all checkbox using jQuery 1.6
3 4 5 |
$('.checkall').click(function () { $(this).parents().find(':checkbox').prop('checked', $(this).prop('checked')); }); |
And for HTML
5 6 7 8 9 10 |
<input type="checkbox" class="checkall" name="checkall" /> Check All <ul> <li><input type="checkbox" value="1" name="id[]" /> One</li> <li><input type="checkbox" value="2" name="id[]" /> Two</li> <li><input type="checkbox" value="3" name="id[]" /> Three</li> </ul> |
And you obviously want to put the script inside ready function.
Leave a Reply