If you generate checkboxes and labels dynamically, or just don't feel like assigning ids to all of your checkboxes and corresponding for attributes to all of your labels, here's a quick jQuery snippet to take care of this:

$('input[type="checkbox"] + label').click(function() {
  $(this).prev().attr('checked', !$(this).prev().attr('checked'));
});

This has the added advantage of minimizing your HTML markup.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *