View Full Version : Setting table cell style attributes

06-19-2007, 03:01 AM
given a cell from a table...
function Tbl_GetCell(tbl, row, col)
var theRow = tbl.getElementsByTagName("tr")[row];
return theRow.getElementsByTagName("td")[col];

I can set attributes like width, height, and align, but how can I set cell style info?

cell = GetCell(tbl,row,col)
these work fine... cell.align = "center"; cell.height = 22;
but this doesn't... cell.style = "font-weight: bold; text-decoration: blink"


06-19-2007, 05:49 AM
cell.style.fontWeight = "bold";
cell.style.textDecoration = "blink";
But it's better to just set the CSS classname so that the code is shorter and all the properties are set at once.

<style type="text/css">
.test {
font-weight: bold;
text-decoration: blink;
/*...and so on*/

cell.className = "test";

06-19-2007, 07:18 AM
thanks glenn. amazing how the simplest stuff is sometimes so hard to find. you're my hero. thanks again.