title: JQuery: If a table header <th> has a class, add class to table cell <td>
body: <p>Let's say I have the following html:</p>
  
  <pre><code>&lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th class="alignRight"&gt;Header1&lt;/th&gt;
              &lt;th&gt;Header2&lt;/th&gt;
              &lt;th class="alignLeft"&gt;Header3&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;Row1&lt;/td&gt; //Add class="alignRight"
              &lt;td&gt;Row1&lt;/td&gt;
              &lt;td&gt;Row1&lt;/td&gt; //Add class="alignLeft"
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Row2&lt;/td&gt; //Add class="alignRight"
              &lt;td&gt;Row2&lt;/td&gt;
              &lt;td&gt;Row2&lt;/td&gt; //Add class="alignLeft"
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Row3&lt;/td&gt; //Add class="alignRight"
              &lt;td&gt;Row3&lt;/td&gt;
              &lt;td&gt;Row3&lt;/td&gt; //Add class="alignLeft"
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>If a TR in the THEAD contains the class "alignRight" or "alignLeft" I would like to apply the same class to the corresponding TD in the TBODY.</p>
  
  <p>I'm using JQuery and have tried the following, but none of them seem to work properly:</p>
  
  <pre><code>$('tr').has('th.alignRight').addClass('th.alignRight');
  $('tr').has('th.alignLeft').addClass('th.alignLeft');
  
  $('thead.tr').has('th.alignRight').addClass('tbody.th.alignRight');
  $('thead.tr').has('th.alignLeft').addClass('tbody.th.alignLeft');
  
  if ($('thead.tr').has('th.alignRight')){
      $('tbody.tr').addClass('th.alignRight');
  }
  
  if ($('thead.tr').has('th.alignRight')){
      $('tbody.tr.td').addClass('alignRight');
  }
  </code></pre>
  
  <p>Any ideas on what could be wrong?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I would like to add that I already iterate through the table using a .each() loop.  I only need to add the condition that if the current table header has that class, add that same class to the table cell.  Adding in an extra iteration during the current iteration sounds like it would lead to performance issues.  Is that true?</p>
  
  <p><strong>LOOP:</strong></p>
  
  <pre><code>function(res) {
      var tbl_body = "";
      $.each(res, function () {
          var tbl_row = "";
          $.each(this, function (k, v) {
  
            //Irrelevant code
  
              tbl_row += "&lt;td&gt;" + v + "&lt;/td&gt;";
          })
          tbl_body += "&lt;tr&gt;" + tbl_row + "&lt;/tr&gt;";
      })
      $("#print").html(tbl_body);
      },
      //Other irrelevant code
  </code></pre>