table tbody tr:even with nested tables.

table tbody tr:even with nested tables.

Hi there!

So, I'm trying to do alternate row backgrounds, which is simple:

  1. $("table tbody tr:even").addClass("even");
The issue I am running into is that I have another table nested inside each row. The parent table gets the 'even' class added to the correct rows, but every row inside the nested table gets the "even" class as well.

So, this is what is happening:

  1. <table>
  2.   <tbody>
  3.     <tr class="even">
  4.       <td>
  5.         <table>
  6.           <tbody>
  7.             <tr class="even">
  8.               <td></td>
  9.             </tr>
  10.             <tr class="even">
  11.               <td></td>
  12.             </tr>
  13.           </tbody>
  14.         </table>
  15.       </td>
  16.     </tr>
  17.     <tr>
  18.       <td>
  19.         <table>
  20.           <tbody>
  21.             <tr>
  22.               <td></td>
  23.             </tr>
  24.             <tr>
  25.               <td></td>
  26.             </tr>
  27.           </tbody>
  28.         </table>
  29.       </td>

  30.     </tr>
  31.   </tbody>
  32. </table>
If anyone could give me some insight on the best way to accomplish what I'm going for, it'd be much appreciated! Thanks!