check all checkbox

check all checkbox

I am trying to create a check all checkbox.  Here is my code:
$('#checkall').click(function () {
$('.checkbox').prop('checked', this.checked);
});
$('.checkbox').change(function () {
var check = ($('.checkbox').filter(":checked").length == $('.checkbox').length);
$('#checkall').prop("checked", check);
});

<input name='checkall' id='checkall' type='checkbox' value='' />

<input type="checkbox" name="checkbox" id="<? echo $id ?>" class="checkbox" />

When I select the checkall box, it does not check all of the checkboxes.