SiteKickr Web Development

jQuery to “link” labels with checkboxes

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.