I simply want to check all of the check boxes on a page if a user clicks the "Select All" button.
In the body:
<button id="checkall">Select All</button>
jQuery:
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#checkall').click(function () {
$("input[type=checkbox]").each( function() {
$(this).attr('checked', true);
});
});
</script>
</head>
And the checkboxes are generated by a little bit of php:
echo '<li>';
echo '<input type="checkbox" name="checkbox[]" value="'.$x.'" />'.$x.'<br/>';
echo '</li>';
Can anyone tell me what I'm doing wrong?