Search code examples
javascriptcss-tables

Different CSS style on odd and even rows


Is it possible, using only CSS, to set different styles on odd and even rows for a dynamically generated table without myself setting correct style on each row when I iterate the collection?


Solution

  • I'm not sure this will work cross-browser, i'd prefer jQuery myself, but css-only this should do the trick:

    tr:nth-child(even) { ... }
    tr:nth-child(odd) { ... }