calculated width of span element.

Discussion in 'Javascript' started by Erwin Moller, Sep 5, 2007.

  1. Erwin Moller

    Erwin Moller Guest

    Hi group,

    Can I retrieve the used width of a span element via javascript?
    If so how?
    (I am fine with javascript, but my CSS knowledge leaves a lot to be
    desired.)

    I tried using width, but that only returns the value I use to create the
    span, which is empty in my case.
    I have a variable tekst in the span.
    I googled around but cannot find the right search words.

    Any suggestions?

    TIA

    Regards,
    Erwin Moller
    Erwin Moller, Sep 5, 2007
    #1
    1. Advertising

  2. Erwin Moller wrote:

    > Can I retrieve the used width of a span element via javascript?


    Try whether
    spanElement.offsetWidth
    gives you the width you are looking for:
    <URL:http://msdn2.microsoft.com/en-us/library/ms534304.aspx>




    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Sep 5, 2007
    #2
    1. Advertising

  3. Erwin Moller

    Erwin Moller Guest

    Johannes Baagoe wrote:
    > Erwin Moller :
    >
    >> Can I retrieve the used width of a span element via javascript? [...] I
    >> googled around but cannot find the right search words.

    >
    >> Any suggestions?

    >
    > You could try "offsetWidth". Not in any official standard, but it might
    > still help. (http://developer.mozilla.org/en/docs/DOM:element.offsetWidth)
    >


    Thanks Martin and Johannes,

    That unofficial property seem to work out just fine. :)
    I actually needed 'left' too, but that was named (surprise suprise)
    offsetLeft.

    accordig to this list:
    http://www.appcreator.com/dom-browser-support
    it is supported by IE5 and above, FF2, and opera 6 and 7.
    That is enough for me. :)
    That should sum up ???... >99% of the webvisitors?

    Thanks!

    Regards,
    Erwin Moller
    Erwin Moller, Sep 5, 2007
    #3
  4. Erwin Moller wrote:
    > accordig to this list:
    > http://www.appcreator.com/dom-browser-support
    > it is supported by IE5 and above, FF2, and opera 6 and 7.
    > That is enough for me. :)
    > That should sum up ???... >99% of the webvisitors?


    142% of all Web statistics are flawed.


    HTH

    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, Sep 5, 2007
    #4
  5. Erwin Moller

    Erwin Moller Guest

    Thomas 'PointedEars' Lahn wrote:
    > Erwin Moller wrote:
    >> accordig to this list:
    >> http://www.appcreator.com/dom-browser-support
    >> it is supported by IE5 and above, FF2, and opera 6 and 7.
    >> That is enough for me. :)
    >> That should sum up ???... >99% of the webvisitors?

    >


    > 142% of all Web statistics are flawed.


    LOL.
    Nothing beats a good laugh at the start of the workingday.
    Thanks. :p

    Erwin
    Erwin Moller, Sep 6, 2007
    #5
    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. Fulio Open

    Can span include span?

    Fulio Open, Jun 26, 2009, in forum: HTML
    Replies:
    5
    Views:
    546
    dorayme
    Jun 26, 2009
  2. Stéphane Klein
    Replies:
    2
    Views:
    1,757
    John Nagle
    Mar 30, 2010
  3. Stefan Behnel
    Replies:
    0
    Views:
    487
    Stefan Behnel
    Mar 29, 2010
  4. Dan Bishop

    DataGrid (body only) contained in <span>...</span> tags

    Dan Bishop, Jun 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    277
    Kilic Beg
    Jun 7, 2004
  5. August Karlstrom

    Getting actual width of span element

    August Karlstrom, Apr 1, 2010, in forum: Javascript
    Replies:
    7
    Views:
    250
    Thomas 'PointedEars' Lahn
    Apr 2, 2010
Loading...

Share This Page