title: CheckBoxList select all options in jQuery
body: <p>I have a CheckBoxList and one of the options is 'All'. I want to select all the options including All if the user checked 'All' and if the user unchecked 'All', I want to clear selections. If they select any other option except 'All', do nothing. 
  Can anyone help me with jQuery to do this? I am using jQuery 1.2.6</p>
  
  <pre><code>&lt;table border="0" onclick="SelectMe(this);" id="one"&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type="checkbox" checked="checked" name="one$0" id="one_0"/&gt;&lt;label for="one_0"&gt;All&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="checkbox" name="two$1" id="two_1"/&gt;&lt;label for="two_1"&gt;Option One&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="checkbox" name="three$2" id="three_2"/&gt;&lt;label for="three_2"&gt;Option Two&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="checkbox" name="four$3" id="four_3"/&gt;&lt;label for="four_3"&gt;Option Three&lt;/label&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type="checkbox" name="five$4" id="five_4"/&gt;&lt;label for="five_4"&gt;Option Four&lt;/label&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p></p>
  
  <p>THANKS ALL FOR HELPING OUT. HERE IS MY ANSWER -</p>
  
  <p>Bind this function to onclick attribute for each of checkboxlist.items</p>
  
  <pre><code>function selectAll(box) { 
  
   //check if this is 'All' checkbox
  
   var isAll = ($(box).next('label').text() == 'All');
  
   //get the checkboxlist
  
   var theList = $(box).parents('table:first'); 
  
    //if 'All' is checked/clicked, check all options
  
    if (isAll) {
      var check = theList.find('input:checkbox')[0].checked; 
       $.each(theList.find('input:checkbox'), function(i, v) {
          v.checked = check;
       });
    } 
  
   // check 'All' option if all other checkboxes are checked     
   else {
       var allchecked = true;
       $.each(theList.find('input:checkbox'), function(i, v) { 
           if(i) if (!v.checked) allchecked = false;
       });
       theList.find('input:checkbox')[0].checked = allchecked; 
  }
  </code></pre>