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, Jun 18, 2006
    #1
    1. Advertisements

  2. No-one got any suggestions?


     
    Stephen Poley, Jun 20, 2006
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.