title: jQuery select/deselect all and individual checkboxes within closest table
body: <p>I have dynamic grid-based tables in the application I am developing.</p>
  
  <p>The following code works, but I need a little functionality added to it:</p>
  
  <p><strong>Current script does the following:</strong></p>
  
  <ol>
  <li>script sees first checkbox.</li>
  <li>click first checkbox selects/deselects all checkboxes within the closest table.</li>
  </ol>
  
  <p><strong>New functionality wanted:</strong></p>
  
  <ol start="3">
  <li>script sees first checkbox.</li>
  <li>click first checkbox selects/deselects all checkboxes within the closest table.</li>
  <li><strong>select/deselect individual checkboxes in table</strong></li>
  </ol>
  
  <p>here is the jquery: </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
  
  //this code works for select ALL, but not individual checkbox select/deselect; 
  $('td input:checkbox').click(function(e) {
    var table = $(e.target).closest('table');
    $('td input:checkbox', table).attr('checked', e.target.checked);
    });
  
  });
  &lt;/script&gt;
  </code></pre>