The small jQuery snippet below will make those plain old labels that follow checkboxes and radio buttons active. That is, they will activate/deactivate the checkboxes / radio buttons that they follow in the HTML.

As you can see, this will only affect labels that do not already have a for attribute.

$('form input:checkbox,form input:radio').each(function() {
    if ($(this).next().is('label') && $(this).next().attr('for') == '') {
        $(this).next().click(function(){
            $(this).prev().click();
        });
    }
});

Tags:

Leave a Reply

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