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. Advertisements

  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. Advertisements

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. Jeremy Chapman

    Table cell width

    Jeremy Chapman, Jul 30, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    960
    Jeremy Chapman
    Jul 30, 2003
  2. AndrewF
    Replies:
    1
    Views:
    1,039
    Bruce Barker
    Oct 10, 2005
  3. Sean Jorden
    Replies:
    1
    Views:
    750
    laurie
    Aug 19, 2003
  4. Mr. x
    Replies:
    1
    Views:
    675
    Hywel Jenkins
    Nov 29, 2003
  5. Phillip Roncoroni
    Replies:
    14
    Views:
    1,387
    Toby A Inkster
    Apr 5, 2004
  6. =?ISO-8859-1?Q?L=FCpher_Cypher?=

    Problem with table cell width

    =?ISO-8859-1?Q?L=FCpher_Cypher?=, Mar 27, 2005, in forum: HTML
    Replies:
    4
    Views:
    1,128
    Lauri Raittila
    Mar 29, 2005
  7. Replies:
    0
    Views:
    636
  8. Fabian Vilers

    Table cell width fixed size

    Fabian Vilers, Apr 24, 2006, in forum: HTML
    Replies:
    11
    Views:
    95,392
    Rex the Strange
    Aug 19, 2009
Loading...