bgcolor for alternative rows in a table dynamically using CSS

css-tables, javascript

Solution

Use :nth-child() pseudo class

tr:nth-child(odd){
    background-color:green
}
tr:nth-child(even){
    background-color:yellow
}​

DEMO

Here is few more selector example.

Problem

How to give two different bgcolor for alternative rows in a table dynamically using CSS. I don't want to use jQuery for solving this problem.

Original source