jQuery Add behavior to matching checkboxes in table
<p>I have this table of data with labels and checkboxes. </p>

<p>It's currently set up for the primary row checkboxes to click simultaneously. This table also has sub rows for each primary row, and I need to add behavior to the sub rows where the identical labels also simultaneously click. For example: when I check the 1st sub row of primary row A, then the 1st sub row of primary row B will also be checked. </p>

<p>The table I'm currently working with is structured the same way as far as IDs and classes go. </p>

<p>Summary of what I'm trying: When clicking the checkbox of a sub row, its identical sub row checkbox below is also checked.</p>

<p>Do I add the sub rows to an array and somehow scan through them to identify a match when clicking the checkbox? Could someone please point me in the right direction on how to approach this? Thanks. </p>

<p><a href="http://jsfiddle.net/c7EcH/" rel="nofollow">http://jsfiddle.net/c7EcH/</a></p>

<pre><code>$(document).ready(function() {
    $("label:contains('PRIMARY ROW A')").closest('tr').attr('id', 'prime-row-a');
    $("label:contains('PRIMARY ROW B')").closest('tr').attr('id', 'prime-row-b');
    var primeRowA = $("label:contains('PRIMARY ROW A')").prev('input');
    var primeRowB = $("label:contains('PRIMARY ROW B')").prev('input');

    primeRowA.change(function(){
        primeRowB.attr('checked', $(this).is(':checked'));
    });
    primeRowB.change(function(){
        primeRowA.attr('checked', $(this).is(':checked'));
    });
});  

&lt;table width="550" border="0" cellspacing="0" cellpadding="5"&gt;
 &lt;tr&gt;
   &lt;td&gt;
     &lt;input type="checkbox"&gt;
     &lt;label&gt;&lt;span&gt;PRIMARY ROW A&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
   &lt;td&gt;
     &lt;input type="checkbox"&gt;
     &lt;label&gt;&lt;span id="01"&gt;01 - SUB ROW A&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
   &lt;/tr&gt;
 &lt;tr&gt;
   &lt;td&gt;
    &lt;input type="checkbox"&gt;
    &lt;label&gt;&lt;span id="02"&gt;02 - SUB ROW B&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
   &lt;td&gt;
    &lt;input type="checkbox"&gt;
    &lt;label&gt;&lt;span id="03"&gt;03 - SUB ROW C&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
   &lt;/tr&gt;
 &lt;tr&gt;
   &lt;td&gt;
    &lt;input type="checkbox"&gt;
    &lt;label&gt;&lt;span&gt;PRIMARY ROW B&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
    &lt;input type="checkbox"&gt;
    &lt;label&gt;&lt;span id="01"&gt;01 - SUB ROW A&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
   &lt;input type="checkbox"&gt;
   &lt;label&gt;&lt;span id="02"&gt;02 - SUB ROW B&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
 &lt;/tr&gt;
 &lt;tr&gt;
  &lt;td&gt;
   &lt;input type="checkbox"&gt;
   &lt;label&gt;&lt;span id="03"&gt;03 - SUB ROW C&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
 &lt;/tr&gt;
&lt;/table&gt;
</code></pre>
