Saturday, April 09, 2005

change the background color of a table cell by javascript code

There are some javascript about changing the background color of a table cell around the web. I don't know why people post that, but I made one with my code that access table cell.

getTableCell( "aTable", 1, 2 )
 .style.backgroundColor="blue";

Labels: ,

Tuesday, April 05, 2005

access table cell via javascript 2

Actually, from what I have tested,

 TableId.rows[ i ].cells[ j ]
works fine.

But some people say there are some problems with Safari. I didn't see problems yet.

Labels: ,

Wednesday, March 30, 2005

Javascript code to access table cell via id

function getTableCell(id, row, cell){
    var vRow = document.getElementById( id ).rows[ row ];
    var i=0, j=0;
    for(;i < vRow.childNodes.length; i ++ ){
     if( "TD" == vRow.childNodes[ i ].nodeName ){
      if( j == cell ) return vRow.childNodes[ i ];
      j ++;
     }
    }
    return null;
   }

Tested on Firefox 1.02, IE6, Safari 1.2

Labels: ,