Skip to content

Instantly share code, notes, and snippets.

@mynameispj
Created August 2, 2012 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mynameispj/3238866 to your computer and use it in GitHub Desktop.
Save mynameispj/3238866 to your computer and use it in GitHub Desktop.
Zebra striping table rows, resetting on specific table rows...
$('tbody > tr').each(function(){
if ($(this).hasClass('header')) {
counter=1;
} else {
if (counter == 1) {
$(this).addClass('even');
counter++;
} else if (counter == 2) {
$(this).addClass('odd');
counter--;
}
}
})
<tr> <!--want no class, as its a header, and also want to reset the zebra striping-->
<th colspan="2" class="header" >
<strong>Body type</strong>
</strong></td>
</tr>
<tr> <!--want class of 'even'-->
<td><strong>Body type</strong></td>
<td>Mid-size SLR</td>
</tr>
<tr> <!--want no class, as its a header, and also want to reset the zebra striping-->
<th colspan="2" >
<strong>Sensor</strong>
</strong></td>
</tr>
<tr> <!--want class of 'even'-->
<td><strong>Max resolution (px)</strong></td>
<td>7360 x 4912</td>
</tr>
<tr> <!--want class of 'odd'-->
<td><strong>Effective pixels</strong></td>
<td>36.3
<span >megapixels</span>
</td>
</tr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment