Obtaining the width of a table-cell

S

Stephen Poley

I have been trying to do something which should be quite simple: write a
cross-browser script which, as part of its function, involves finding
what the displayed width of a table cell is.

After several hours of Googling and trying test pages, I'm baffled.

Lots of webpages claim that one uses OffsetWidth. However this does not
return the width: it appears to return width+padding+border. Microsoft's
own documentation claims that IE does indeed return the width in
standards mode, but I've tested it and it doesn't (at least for table
cells). Opera and Firefox appear in this respect to be bug-compatible
with IE.

The style.width property is useless unless the width has been set
explicitly on this element. Similarly for currentStyle["width"].

Firefox provides the decidedly baroque
document.defaultView.getComputedStyle(x, "").getPropertyValue("width")
which seems to work. Opera recognises it, but provides the same broken
result as OffsetWidth. IE does not support this method.

How can one get hold of this rather elementary piece of information in
browsers other than Firefox/Mozilla?
 
S

Stephen Poley

No-one got any suggestions?


I have been trying to do something which should be quite simple: write a
cross-browser script which, as part of its function, involves finding
what the displayed width of a table cell is.

After several hours of Googling and trying test pages, I'm baffled.

Lots of webpages claim that one uses OffsetWidth. However this does not
return the width: it appears to return width+padding+border. Microsoft's
own documentation claims that IE does indeed return the width in
standards mode, but I've tested it and it doesn't (at least for table
cells). Opera and Firefox appear in this respect to be bug-compatible
with IE.

The style.width property is useless unless the width has been set
explicitly on this element. Similarly for currentStyle["width"].

Firefox provides the decidedly baroque
document.defaultView.getComputedStyle(x, "").getPropertyValue("width")
which seems to work. Opera recognises it, but provides the same broken
result as OffsetWidth. IE does not support this method.

How can one get hold of this rather elementary piece of information in
browsers other than Firefox/Mozilla?
 

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,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top