Alternating row colours with Javascript & CSS

Searches through the document for tables with the "alternateRows" class, and then sets the class of even rows to "even" for appropriate rows in that table, allowing for easy styling via CSS.

Alternating
1 2 3 4
A 31.00 22.50 40.00 35.00
B 40.00 20.00 16.00 25.00
C 16.33 5.33 7.99 25.25
D 16.00 5.99 22.50 25.00
C 16.33 5.33 7.99 25.25
D 16.00 5.99 22.50 25.00
C 16.33 5.33 7.99 25.25

 

Not Alternating
1 2 3 4
A 31.00 22.50 40.00 35.00
B 40.00 20.00 16.00 25.00
C 16.33 5.33 7.99 25.25

 

Back

 

Keywords: Alternating Rows, Colour, Color, colours, colors, Javascript, standards, unobtrusive javascript