I would do it like that:

<div>
        <a href="javascript:;" class="selectAll">Select All</a> <a
href="javascript:;" class="deselectAll">Deselect All</a>

        <label><input type="checkbox" />Item 1</label><br/>
        <label><input type="checkbox" />Item 2</label><br/>
        <label><input type="checkbox" />Item 3</label><br/>
        <label><input type="checkbox" />Item 4</label><br/>
</div>

<div>
        <a href="javascript:;" class="selectAll">Select All</a> <a
href="javascript:;" class="deselectAll">Deselect All</a>

        <label><input type="checkbox" />Item 1</label><br/>
        <label><input type="checkbox" />Item 2</label><br/>
        <label><input type="checkbox" />Item 3</label><br/>
        <label><input type="checkbox" />Item 4</label><br/>
</div>

and the js:

$(document).ready(function() {
  $(".selectAll").click(function() {
    $(this).parent().find(":input").attr("checked", "checked");
  });
  $(".deselectAll").click(function() {
    $(this).parent().find(":input").removeAttr("checked");
  });

});

On 9 Okt., 22:24, bmclaughlin <[EMAIL PROTECTED]> wrote:
> Hello all,
> I need a "select all" to work, and be limited to, multiple sections on
> page.
>
> How many of these sections there will be on a page is not known.
> Each section needs its own "select all" trigger.
>
> For example: (but how many of these groups there would be would be
> unknown)
>
> <div>
>         <a href="">Select All</a> <a href="">Deselect All</a>
>
>         <label><input type="checkbox" />Item 1</label><br/>
>         <label><input type="checkbox" />Item 2</label><br/>
>         <label><input type="checkbox" />Item 3</label><br/>
>         <label><input type="checkbox" />Item 4</label><br/>
> </div>
>
> <div>
>         <a href="">Select All</a> <a href="">Deselect All</a>
>
>         <label><input type="checkbox" />Item 1</label><br/>
>         <label><input type="checkbox" />Item 2</label><br/>
>         <label><input type="checkbox" />Item 3</label><br/>
>         <label><input type="checkbox" />Item 4</label><br/>
> </div>
>
> <div>
>         <a href="">Select All</a> <a href="">Deselect All</a>
>
>         <label><input type="checkbox" />Item 1</label><br/>
>         <label><input type="checkbox" />Item 2</label><br/>
>         <label><input type="checkbox" />Item 3</label><br/>
>         <label><input type="checkbox" />Item 4</label><br/>
> </div>
>
> Thank you in advance.

Reply via email to