/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
.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>
URL: http://davidwalsh.name/sugar/mootools/page/4
Comments
