faqts : Computers : Programming : Languages : JavaScript : Tables

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

53 of 66 people (80%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do I find all cells in a TABLE row?
How do I find all cells in a TABLE row?
How do I find all cells in a TABLE row?

Mar 10th, 2000 04:01
Martin Honnen,


Only IE4+ and NN6 through their full DOM implementation allow that. 
Every HTMLTableRowElement has a
  cells
property being an array of all HTMLTableCellElements in the row. So get 
a reference to a row for instance with
  var row = 
    document.all ? // IE
      document.all['tableID']
    document.getElementById ? // NN6 or other DOM compliant browser
      document.getElementById('tableID') : null;
or just inside an event handler e.g.
  <TR ONMOUSEOVER="var row = this; ...">
and then script
  if (row) // browser supports DOM access
    // script row.cells e.g color cells alternatingly
    for (var c = 0; c < row.cells.length; c++)
      if (c % 2 == 0)
        row.cells[c].bgColor = 'red';
      else
        row.cells[c].bgColor = 'green';

NN4 doesn't have any DOM support for accessing TABLE elements or TABLE 
rows (TR) elements nor does it have real DOM support to access TABLE 
cells (TD) elements but
http://www.faqts.com/knowledge-base/view.phtml/aid/979/fid/192/lang/en
shows some layer based tricks to get onmouseover/out/click handling for 
TABLE cells nevertheless.