Stripey tables — resources
Description
This source code has an accompanying article
describing the use of the Document Object Model (DOM) and JavaScript to
add guide stripes to <table>
elements.
For a working example, examine the page source for the Waxheadlines.
JavaScript
function tableStripe(p_strId, p_strClass, p_bOdd) {
var l_Table = document.getElementById(p_strId);
if(l_Table.rows) {
// Search through the table for the row elements and
// apply the p_strClass to the odd, or even ones depending
// on the Boolean p_bOdd
for(var l_iIndex = 0; l_iIndex
Optimization! — 15-Mar-2004: Following a suggestion by my
friend Nigel, we can make the algorithm more
efficient by discarding the modulo arithmetic (of which I was very proud!) and
realising (d’oh) that, since we’ve got an ordered list of rows, we
can loop through visiting only every second row...
function tableStripe(p_strId, p_strClass, p_bOdd) {
var l_Table = document.getElementById(p_strId);
var l_iIndex = ( p_bOdd ? 1 : 0 );
if(l_Table.rows) {
for( ; l_iIndex
Copyright © 1997-2005 Peter Asquith — All rights reserved
Articles