|
| Obtaining the width of an element in script |
 |
Sat, 10 Jun 2006 08:26:06 +020 |
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 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 appears 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 - but not in Opera or IE.
A previous post in one of the Opera groups recommended style.pixelWidth
but this doesn't return anything for me.
For Opera (and IE) I cannot work out how to do this. How can one get
hold of this rather elementary piece of information?
--
|
| Post Reply
|
|
|
|
|
|
|
|
|
|