Return to Snippet

Revision: 59189
at August 23, 2012 01:27 by dnnsldr


Initial Code
$(function () {
    $('.checkall').click(function () {
        $(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
    });
});

Initial URL
http://briancray.com/posts/check-all-jquery-javascript

Initial Description
How does it work?

This code checks/unchecks all checkboxes within the same fieldset. Simple and semantic.
HTML Setup

Add checkboxes however you like, just make sure they are within the same fieldset.

<fieldset>
    <!-->
    <div><input> Check all</div>
    <div><input> Checkbox</div>
    <div><input> Checkbox</div>
    <div><input> Checkbox</div>
</fieldset>
<fieldset>
    <!-->
    <div><input> Checkbox</div>
    <div><input> Checkbox</div>
    <div><input> Checkbox</div>
</fieldset>

Initial Title
jQuery \"Check All\"

Initial Tags
jquery

Initial Language
JavaScript