title: How to select multiple checkboxes with the same class but depending on which items have been selected
body: <p>I have a table with multiple rows, in this table each row has it's checkbox and a text field (this text field contains class XXX, but is different per row, although sometimes two of more share the same class).</p>
  
  <p>Now I want, when a user selects checkbox 1 (textfield has the class "A") and checkbox 5 (textfield has the class "B") and clicks the button "Select group", to select <strong>all</strong> other checkboxes which have the textfield with class "A" or class "B" in their row.</p>
  
  <p>I was thinking of using <code>$(this).closest</code> but I don't know how jQuery really works, so could anyone point me out in the right direction?</p>
  
  <p>Thanks in advance.</p>
  
  <p><strong>Edit</strong> some html: <a href="http://jsfiddle.net/hg4p6/1/" rel="nofollow">http://jsfiddle.net/hg4p6/1/</a></p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type='checkbox' id='chk1'&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type='text' value='123' class='A'&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type='checkbox' id='chk2'&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type='text' value='518' class='C'&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type='checkbox' id='chk3'&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type='text' value='321' class='B'&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type='checkbox' id='chk4'&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type='text' value='567' class='A'&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;input type='checkbox' id='chk5'&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;input type='text' value='971' class='B'&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td colspan='2'&gt;&lt;input type='button' value='Select same classes' onclick='Funcion'&gt;
          &lt;/td&gt;
      &lt;/tr&gt; 
  &lt;/table&gt;
  </code></pre>
  
  <p>So basically, when you select the first checkbox, it should select the 4th aswell. And if you select the 3rd checkbox, it should select the 5th aswell.</p>