Automatic Coloured Rows | JavaScriptSource

Automatic Coloured Rows

Anton Peck May 30, 2006

General

Tired of adding even and odd classes to your tables to distinguish the rows? This script will do it for you automatically. You can even use it with lists!


Browsers Hits Percent
Mozilla Firefox 15772 73%
Internet Explorer 6 4581 21.2%
Mozilla 442 2%
Opera 122 0.5%
Safari 100 0.4%
Netscape 99 0.4%

Notes

Source Code

Paste this source code into the designated areas.

External file

Paste this code into an external JavaScript file named: autoRows.js


CSS

Paste this code into your external CSS file or in the <style> section within the HEAD section of your HTML document.


Head

Paste this code into the HEAD section of your HTML document.


Body

Paste this code into the BODY section of your HTML document


Leave a Response

(2 comments)

If you just want to color one of the tables (or lists) instead of using document.getElementByTagName("tr"); (for tables) give the table an id and use document.getElementById("myTablesId").getElementsByTagName("tr");

Lee Oct 3, 2007

The script appears to affect all tables (rows) on the page. What If you have several tables on the page, but want to apply the alternate colored rows to only one table? How do you get the script to ignore the other tables?

Jim Williams Sep 8, 2007