This JavaScript will stripe your tables. The colors come from custom attributes in the tbody tag. This will also work in IE 5. |
Over 2000+ free Javascript
at JavaScriptBank.com Website
/* Powered by DCScript http://geocities.com/seanmhall2003/SeanSoft/ */ function stripe() { if (!document.getElementsByTagName || !document.createElement) return; var x = document.getElementsByTagName("tr"); for (var i=0;iExplanation
This script is fairly simple. First we check if the browser supports the W3C DOM. If it doesn’t, we end the function. Then we get alltr
tags and loop through them.function stripe() { if (!document.getElementsByTagName || !document.createElement) return; var x = document.getElementsByTagName("tr"); for (var i=0;iThen we also see if the tbody
tag has theoc
attribute, which denotes whether the table should be striped or not. If it doesn’t have that attribute or thetr
has a class we skip this row. Then we find out which color should be applied to the row. If it’s an even row we give it the value of theec
attribute. If it’s and odd row we give the value of theoc
attribute.if (!x[i].parentNode.getAttribute("oc") || x[i].className || x[i].parentNode=="THEAD") continue; var col = (i%2==0) ? x[i].parentNode.getAttribute("ec") : x[i].parentNode.getAttribute("oc"); x[i].style.backgroundColor = col;Finally we set theonLoad
event handler and we’re flyin’window.onload = stripe;