Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change table alternative rows colors using jquery?

I have to change colors for alternative rows. one row in "Green" and another one is in "Yellow".

<tr class="ms-viewheader" vAlign="top">
<tr class="">
<tr class="ms-alternating">
<tr class="">
<tr class="ms-alternating">
<tr class="">
<tr class="ms-alternating">
<tr class="">
<tr class="ms-alternating">

I have to skip "ms-viewheader" row and start coloring next sibling. Full row should be in color.

How to do this?

like image 724
James123 Avatar asked Jun 10 '11 19:06

James123


1 Answers

run something like this in javascript

// define the background color for even and odd rows
var bgColors = {
  even: '#eaeaea',
  odd:  '#aeaeae'
};
$("table tr:not(.ms-viewheader):even").css({"backgroundColor":bgColors.even});
$("table tr:not(.ms-viewheader):odd").css({"backgroundColor":bgColors.odd});
like image 100
Teddy Avatar answered Nov 02 '22 07:11

Teddy