Return to Snippet

Revision: 5427
at March 8, 2008 10:52 by gbot


Updated Code
.shade-table	{ /* just to remind us we're using this -- we don't want to write over it later! */ }
.odd		{ background:#ccc; padding:3px; }
.even		{ background:#eee; padding:3px; }

window.addEvent('domready', function() {
	var count = 0;
	$$('table.shade-table tr').each(function(el) {
		el.addClass(count++ % 2 == 0 ? 'odd' : 'even');
	});
});

<table class="shade-table" border="1" cellpadding="5" cellspacing="2"><tbody>
<tr>
<td>1</td>
<td>1</td>
<td>1</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>3</td>
<td>3</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>4</td>
<td>4</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td>5</td>
<td>5</td>
<td>5</td>
</tr>
</tbody></table>

Revision: 5426
at March 8, 2008 10:51 by gbot


Initial Code
.shade-table	{ /* just to remind us we're using this -- we don't want to write over it later! */ }
.odd		{ background:#ccc; padding:3px; }
.even		{ background:#eee; padding:3px; }

Initial URL
http://davidwalsh.name/sugar/mootools/page/4

Initial Description

                                

Initial Title
MooTools alternate table row colors

Initial Tags
table

Initial Language
JavaScript