Checkbox and Radio Btns

by Evan Sharp

HTML

<div>
    <label for="cb1"><input type="checkbox" value="1" name="checkbox" id="cb1" /> I Agree</label>
</div>
<div>
    <label for="rb1"><input type="radio" value="1" name="radio" id="rb1" /> Yes</label>
</div>
<div>
    <label for="rb2"><input type="radio" value="0" name="radio" id="rb2" /> No</label>
</div>

JavaScript

(function($) {
    $.styleForm = function() {
        var s = '[type=radio],[type=checkbox]',
            c = 'checked',
            a = function() {
                $(s).each(function() {
                    var l = $(this).parent().removeClass(c);
                    if ($(s,l).is(':' + c)) l.addClass(c);
                });
            };
        $('body').on('click', s, function() {
            a();
        });
        a();
    };
})(jQuery);

$.styleForm();