I am encountering an issue with alternating row colors in my tables. Even though I have two separate tables, the tr:odd
rule is being applied across both tables.
Below is the HTML for my tables:
<table class='myTable'>
<tr class='myRow'>
<td>row 1</td>
</tr>
<tr class='myRow'>
<td>row 2</td>
</tr>
<tr class='myRow'>
<td>row 3</td>
</tr>
</table>
<hr>
<table class='myTable'>
<tr class='myRow'>
<td>row 1</td>
</tr>
<tr class='myRow'>
<td>row 2</td>
</tr>
</table>
Here is the CSS:
.myAltRowClass { background: #DDDDDC; }
And the JavaScript:
$(".myTable .myRow:odd").addClass('myAltRowClass');
You can view the jsfiddle: http://jsfiddle.net/niner/Sgq9T/
My problem is that the first row of the second table is starting with the alternate color, when it should start with the normal (white) color. Any assistance on this would be greatly appreciated. Thank you.