[thelist] Alternating Rows

Tom Dell'Aringa pixelmech at yahoo.com
Mon Oct 7 14:21:01 CDT 2002


--- Ben Dyer <ben_dyer at imaginuity.com> wrote:

> Obviously, there's a million ways to do alternating row colors but
> every
> one of them requires hardcoding an attribute to each table row or
> assigning
> an attribute programmatically (<CFIF CurrentRow MOD 2 IS
> 0>class="evenrow"</CFIF> and so on).
<snip>

Ben, here is something I use by using the DOM which, if not usable
for you may spark an idea.

function colorRows()
{
table = document.getElementById("your_table_id");
numrows = table.getElementsByTagName("TR").length;

x = 0;
strColor = "#b7c6a9"; //your base color

while(x < numrows)
{
	if(strColor == "#b7c6a9")
	{
		strColor = "#e2e2c5"; //your other color
	}
	else
	{
		strColor = "#b7c6a9"
	}
	table.getElementsByTagName("TR").item(x).style.backgroundColor =
strColor;
	x = x + 1;
}

}

This will work if you change the number of rows, etc. HTH

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com



More information about the thelist mailing list