Thursday, July 31, 2008

Parse html table cells

I wanted to parse a html table and color the TD - s (background).
All of them.
I have a column that has links in it. My basic Idea was to change the background color of the TD when you click the link inside that. That's easy, but without some global (js?) variable, you don't know what was previously clicked, and you might want to turn that "off" :)
Anyways: this is how I did it:





function ParseTableAndColorTheBackground(objTbl, WhatColorShouldItBe)
{
var intNrOfTrs = objTbl.tBodies[0].rows.length;
for (var i=0; i < intNrOfTrs; i++)
{
objTbl.tBodies[0].rows[i].cells[1].style.backgroundColor = WhatColorShouldItBe;
}
}




you have a better way to do this?

comment me pls
;)

No comments: