Identifying width of a table

G

Griff

I have a page with multiple tables, some of which have the class
"ClassA".

I need to identify the widest table whose class is ClassA.

The following JavaScript code returns the table width
("thisTableWidth")
when run in FireFox 2.0, but returns '0' when run in IE6.

Be grateful for any advice for how to get at this value using IE6.

Thanks

Griff
-----------------------------
var thisTableWidth = 0;
var maxTableWidth = 0;

// Get collection of tables
var eachObject = document.getElementsByTagName("table");

// Iterate through each table
for (var i = 0; i < eachObject.length; i++)
{
// Does this table have a class called ClassA?
if (eachObject.className.indexOf('ClassA') != -1)
{
// Attempt to read this table's width
thisTableWidth = eachObject.offsetWidth;

// Is this wider than my last table I checked?
if (thisTableWidth > maxTableWidth)
{
maxTableWidth = thisTableWidth;
}
}
}
 
G

Griff

Found it out...

In IE, the JavaScript is run BEFORE the objects are displayed,
therefore they have a width of 0.

Have to put the Js in a function and call it in the onLoad() page
event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top