Using % on a table width, is it possible to get the width in pixel size?

Discussion in 'Javascript' started by RMZ, Aug 1, 2007.

  1. RMZ

    RMZ Guest

    If you have an HTML table defined like so

    <table border="1" width="100%" height="100%">
    <tr>
    <td>row 1, cell 1</td>
    <td>row 1, cell 2</td>
    </tr>
    <tr>
    <td>row 2, cell 1</td>
    <td>row 2, cell 2</td>
    </tr>
    </table>

    Is it possible using JavaScript to return the width and height pixel
    counts for the width and height of the table?
    RMZ, Aug 1, 2007
    #1
    1. Advertising

  2. RMZ

    Guest

    On Aug 1, 11:10 am, RMZ <> wrote:
    > If you have an HTML table defined like so
    >
    > <table border="1" width="100%" height="100%">
    > <tr>
    > <td>row 1, cell 1</td>
    > <td>row 1, cell 2</td>
    > </tr>
    > <tr>
    > <td>row 2, cell 1</td>
    > <td>row 2, cell 2</td>
    > </tr>
    > </table>
    >
    > Is it possible using JavaScript to return the width and height pixel
    > counts for the width and height of the table?


    If you are willing to use prototype.js (Prototype library
    http://prototypejs.org/api), you can simply call

    $('tableid').getDimensions(); and it will return an object { width: 0,
    height: 0 };
    , Aug 1, 2007
    #2
    1. Advertising

  3. RMZ

    David Mark Guest

    On Aug 1, 2:02 pm, wrote:
    > On Aug 1, 11:10 am, RMZ <> wrote:
    >
    > > If you have an HTML table defined like so

    >
    > > <table border="1" width="100%" height="100%">
    > > <tr>
    > > <td>row 1, cell 1</td>
    > > <td>row 1, cell 2</td>
    > > </tr>
    > > <tr>
    > > <td>row 2, cell 1</td>
    > > <td>row 2, cell 2</td>
    > > </tr>
    > > </table>

    >
    > > Is it possible using JavaScript to return the width and height pixel
    > > counts for the width and height of the table?

    >
    > If you are willing to use prototype.js (Prototype libraryhttp://prototypejs.org/api), you can simply call
    >
    > $('tableid').getDimensions(); and it will return an object { width: 0,
    > height: 0 };


    Assuming the table does not have a display style of "none", you can
    use the offsetWidth and offsetHeight properties of the table element.
    That is what Prototype sends back for displayed elements. This will
    save you 70K of extra page weight.
    David Mark, Aug 2, 2007
    #3
    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. Sangeeta

    Pixel Width of Char in Web App

    Sangeeta, Aug 14, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,085
    Jerry III
    Aug 15, 2003
  2. Sean Jorden
    Replies:
    1
    Views:
    586
    laurie
    Aug 19, 2003
  3. Replies:
    1
    Views:
    727
    Beauregard T. Shagnasty
    Dec 29, 2007
  4. André Wagner

    Fastest pixel by pixel operation

    André Wagner, Mar 17, 2008, in forum: Java
    Replies:
    12
    Views:
    1,030
    Larry A Barowski
    Mar 19, 2008
  5. douglasc
    Replies:
    0
    Views:
    175
    douglasc
    Nov 21, 2003
Loading...

Share This Page