wrote on 09 dec 2005 in comp.lang.javascript
:
I am generating a html based table with multiple rows of data coming
in real time from a postgres DB. The underlying technology is java
based however the front end is html.
now i am unable to alternate the colour of every row so that the table
is lot more readable. can anyone suggest a javascript or even a css
script which will alternate the row colours irrespective of the number
of rows.
I suggested this in 2003 on usenet:
[use childNodes(1) if you have a <thead> before the <tbody>,
even if the <tbody> is not explicitly declared]
<script type='text/javascript'>
i=0
x=document.getElementById('tbl').childNodes(0).chi ldNodes
while(i< x.length) {
if (i % 2)
x(i).style.backgroundColor="#eee"
else
x(i).style.backgroundColor="#aaa"
i++
}
</script>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)