Select/Deselect All Checkboxes
HTML
<label><input type="checkbox" name="sample" class="selectall"/> Select all</label>
<div id="checkboxlist">
<label><input type="checkbox" name="sample[]" checked='true' /> This is a checkbox1</label><br />
<label><input type="checkbox" name="sample[]"/> This is a checkbox2</label><br />
<label><input type="checkbox" name="sample[]" checked='true' /> This is a checkbox3</label><br />
<label><input type="checkbox" name="sample[]"/> This is a checkbox4</label><br />
</div>
CSS
div {
color: #C00;
font-family: Tahoma, Geneva, sans-serif;
font-size: 10px;
margin-top: 10px;
width: 500px;
}
input {
padding-right: 10px;
}
CoffeeScript
boxes = $('#checkboxlist [type=checkbox]')
selectAll = $('.selectall')
toggleCheckboxes = ->
if $(this).is ':checked' then boxes.prop "checked", true else boxes.prop "checked", false
selectAll.on 'click', toggleCheckboxes