CoderZone.org

Category: >> JavaScript >> Make alternating color table rows automatically Bookmark and Share

<< lastnext >>

Snippet Name: Make alternating color table rows automatically

Description: Makes a given table have striped (alternating color) table rows automatically.

Comment: (none)

Author: CoderZone
Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: June 13th, 2010

var tables = getElementsByClassName("dataTable");
 
for (var i = 0, ii = tables.length; i < ii; i++)
{
	var tbody = tables[i].getElementsByTagName("tbody");
 
	for(j = 0, jj = tbody.length; j < jj; j++)
	{
		var rows = tbody[j].getElementsByTagName("tr");
 
		for(k = 1, kk = rows.length; k < kk; k += 2)
		{
			rows[k].className = "alt";
		}
	}
}
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 5