toll free: (866) 611-9441

Alternating Row Background Color For Multiple Tables With jQuery, In One Line

OK, this one is very easy to follow.
Let’s say we have two tables that we need to zebra strip.
In our .css  file we will create a class for the alternating color row, let’s call it “.alternatecolor”.
After that, all we need to do is to assign the class “strippedtable” to each table we need to affect.
<table class=”strippedtable”></table>
jQuery will take care of the rest upon finishing loading the document. Just use the snippet below.

$(document).ready(function(){
$(“.strippedtable > tbody > tr:nth-child(even)”).addClass(“alternatecolor”);
});

Leave a Reply