I want to color every second row of a table. While every regular table can be colored using this:
$('tr:odd').css( "background-color", "orange" );
In my case there are several rowspan
, what makes the task more difficult.
This is my desired output:
Using this code above doesn't lead to the desired result:
$('tr:odd').css("background-color", "orange");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1">
<tr>
<td>Col 1</td>
<td>Col 2</td>
<td>Col 3</td>
</tr>
<tr>
<td rowspan="2">Col 1</td>
<td>Col 2</td>
<td rowspan="2">Col 3</td>
</tr>
<tr>
<td>Col 1</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
<td>Col 3</td>
</tr>
<tr>
<td rowspan="2">Col 1</td>
<td rowspan="2">Col 2</td>
<td>Col 3</td>
</tr>
<tr>
<td>Col 1</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
<td>Col 3</td>
</tr>
</table>