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 7 of 10 people (70%) answered Yes

Entry

How do I find all TABLEs in a document?
How do I find all TABLEs in a document?
How do I find all TABLEs in a document?

Mar 10th, 2000 03:28
Martin Honnen,


Only IE4+ and NN6 trough their full DOM implementation allow that.
IE4+:
  var allTables = document.all.tags('TABLE');
NN6 (and IE5):
  var allTables = document.getElementsByTagName('TABLE');
So for crossbrowser code you write
  var allTables = document.all ?
    document.all.tags('TABLE') :
    document.getElementsByTagName ? 
    document.getElementsByTagName('TABLE') : new Array();
Then you can loop through allTables.

Of course if you just want to access a particular table give it an ID 
attribute e.g.
  <TABLE ID="aTable">
and then script 
  var table = document.all ? document.all['aTable'] :
    document.getElementById ?
    document.getElementById('aTable') : null;
  if (table)
    // script table for instance loop through table.rows