I have been banging my head on this one for too long.
I have a basic table (all the TR’s except the ones that include th’s are classes with classme)
<table>
<tr class="classme"><td>1</td></tr>
<tr class="classme"><td>1a</td></tr>
<tr class="classme"><td>2</td></tr>
<tr class="classme"><td>2a</td></tr>
<tr><th>skip me</th></tr>
<tr class="classme"><td>3</td></tr>
<tr class="classme"><td>3a</td></tr>
<tr ...><td>4</td></tr>
<tr ...><td>4a</td></tr>
<tr ...><td>5</td></tr>
<tr><td>5a</td></tr>
<tr><td>8</td></tr>
<tr><td>8a</td></tr>
<tr><td>9</td></tr>
<tr><td>9a</td></tr>
<tr><td>10</td></tr>
<tr><td>10a</td></tr>
<tr><th>skip me</th></tr>
<tr><td>11</td></tr>
<tr><td>11a</td></tr>
<tr><td>12</td></tr>
<tr><td>12a</td></tr>
</table>
That I would like to stripe with a tr background color.
I am using jQuery and have found a few posts on here and Google relate to the stripping but have failed to find something that skips arbitrary rows.
I have attempted…
$("tr:nth-child(4n)").addClass("alt").prev().addClass("alt");
which works great, but it counts the ones I want to skip.
and
$("tr:not(tr th):nth-child(4n)").addClass("alt").prev().addClass("alt");
with no luck. I even tried to assign a variable to the result of
var trs = $(".classme");
$(trs + ":nth-child(4n)").addClass("alt").prev().addClass("alt");
but it still counted applied the style incorrectly.
How do I set a set of selected elements such that the rows I want to exclude are not in the count when the add class is put onto the element?
Edit:
I would like to stripe (in the table example) 1,1a,3,3a,5,5a. So I consider 1 and 1a to be a group. I want to stripe every other group.
Edit:
updated with jsFiddle
Try this:
Edit .skips lower th tag now
DEMO http://jsfiddle.net/YXDMH/
EDIT: all rows without
THincludedhttp://jsfiddle.net/YXDMH/1/