Obtaining the width of a table-cell

Discussion in 'Javascript' started by Stephen Poley, Jun 18, 2006.

  1. 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
    Stephen Poley, Jun 18, 2006
    #1
    1. Advertising

  2. 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
    Stephen Poley, Jun 20, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. AndrewF
    Replies:
    1
    Views:
    758
    Bruce Barker
    Oct 10, 2005
  2. Sean Jorden
    Replies:
    1
    Views:
    591
    laurie
    Aug 19, 2003
  3. Replies:
    0
    Views:
    512
  4. Charlie

    Obtaining glyph width in Python

    Charlie, Jul 4, 2005, in forum: Python
    Replies:
    1
    Views:
    397
    Andreas Lobinger
    Jul 4, 2005
  5. Sharlet

    Obtaining Width and Height for an Image

    Sharlet, Aug 7, 2003, in forum: ASP General
    Replies:
    5
    Views:
    97
    Chris Barber
    Aug 8, 2003
Loading...

Share This Page