$('').prependTo('th.select-all').click(function() { $('input:checkbox:not(.select-all-checkbox)', this.form).each(function() { this.checked = $('.select-all-checkbox')[0].checked; $(this).parents('tr').toggleClass('selected'); }); });