This function is need to work around A bug in IE related to element attributes function Hasclass (obj) { var result = false; if (Obj.getattributenode ("class")!= null) { result = Obj.getattributenode ("class"). Value; } return result; } function stripe (ID) { The flag we ' ll use to keep track of Whether the current row is odd or even var even = false;
If arguments are provided to specify the colours Of the even & odd rows, then use the them; Otherwise use the following defaults: var evencolor = arguments[1]? ARGUMENTS[1]: "#fff"; var oddcolor = arguments[2]? ARGUMENTS[2]: "#eee";
Obtain a reference to the desired table If no such table exists, abort var table = document.getElementById (ID); if (! table) {return;}
By definition, tables can have more than one tbody element, so we'll have to get the list of child <tbody>s var tbodies = table.getelementsbytagname ("tbody"); and iterate through them ... for (var h = 0; h < tbodies.length; h++) {
Find All <tr> Elements ... var trs = Tbodies[h].getelementsbytagname ("tr");
... and iterate through them for (var i = 0; i < trs.length; i++) { Avoid rows that have a class attribute or BackgroundColor style if (!hasclass (trs[i]) &&! Trs[i].style.backgroundcolor) {
Get all the cells in this row ... var tds = Trs[i].getelementsbytagname ("TD");
and iterate through them ... for (var j = 0; J < Tds.length; J + +) {
var mytd = tds[j]; Avoid cells that have a class attribute or BackgroundColor style if (! hasclass (MYTD) &&! Mytd.style.backgroundColor) {
Mytd.style.backgroundColor = even? Evencolor:oddcolor;
} } } Flip from odd to even, or vice-versa even =! even; } } }
|