Forum:How to alternate row colour in a table?

Is it possible to create a layout on a page that contains a table so that when a new row is added to the table the background colour of the rows will change automatically?

For instance I have a table with the following table:

but if I wanted to add another row in between rows 1 and 2 it would mean that I would have to modify the bg color of every row to alternate the colors. This may be easy for tables with 10 or so rows but what about if I have 50 or more? Can code be put in to automate the alternating colour? At the moment I simply include bgcolor="#efefef" for providing the colours

150.101.2.50 01:36, 7 December 2007 (UTC)


 * Yup, if you use a sortable table it'll work. Just add class="sortable" to the table, and do the coloring to stuff inside of MediaWiki:Common.css. The sortable class's JS will add .odd and .even classes to the rows. ~ NOTASTAFF Daniel Friesen (DanTMan, Nadir Seen Fire) (talk) (tricks) (current topic) Dec 7, 2007 @ 02:25 (UTC)


 * Seems like this function (.odd & .even class) has been remove from the sortable js --


 * I believe though, that most people put it on Common.js . --DaNASCAT 16:33, November 13, 2009 (UTC)


 * It hasn't been removed, you just need to turn it on (it's turned off by default). Put the following line in Common.js: "var ts_alternate_row_colors = true;" If you want to see a way to do it without using sortable tables, look at my wiki's javascript. Surgo 17:09, November 13, 2009 (UTC)