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?

49 of 57 people (86%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I find all the rows in a TABLE?
How do I find all the rows in a TABLE?
How do I find all the rows in a TABLE?

Mar 10th, 2000 04:06
Martin Honnen,


Only IE4+ and NN6 through their full DOM implementation allow that. 
Every HTMLTableElement has a property 
  rows
which contains all the HTMLTableRowElements in the table. So you get a 
reference to a table
  var table = 
    document.all ? // IE
      document.all['tableID'] :
    document.getElementById ? // NN6 or other DOM compliant browser
      document.getElementById('tableID') :
        null; // no access
and then you script table.rows for instance
  if (table) // browser supports TABLE access
    // use table.rows for instance color rows alternatingly
    for (var r = 0; r < table.rows.length; r++)
      if (r % 2 == 0)
        table.rows[r].bgColor = 'red';
      else
        table.rows[r].bgColor = 'green';

NN4 doesn't provide DOM access to TABLE elements nor to TABLE rows (TR 
elements).
http://www.faqts.com/knowledge-base/view.phtml/aid/979/fid/192/lang/en
http://www.faqts.com/knowledge-base/view.phtml/aid/980/fid/192/lang/en
show how to use layers to achieve nevertheless onmouseover/out/click 
handling for table cells and table rows.