Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Obtaining the width of a table-cell

Reply
Thread Tools

Obtaining the width of a table-cell

 
 
Stephen Poley
Guest
Posts: n/a
 
      06-18-2006
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?

--
Stephen Poley
 
Reply With Quote
 
 
 
 
Stephen Poley
Guest
Posts: n/a
 
      06-20-2006
No-one got any suggestions?


On Sun, 18 Jun 2006 08:49:14 +0200, Stephen Poley
<> wrote:

>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?


--
Stephen Poley
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox width scaling to width of data not width of page? AndrewF ASP .Net 1 10-10-2005 04:38 PM
JComboBox width, dropdown list width Xu Java 11 07-15-2005 11:54 PM
Obtaining glyph width in Python Charlie Python 1 07-04-2005 01:33 PM
Obtaining window height and width Chris Beall Javascript 3 02-27-2005 10:44 PM
Obtaining Width and Height for an Image Sharlet ASP General 5 08-08-2003 06:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57