#1
  1. Über nübe
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Babylon 4
    Posts
    240
    Rep Power
    11

    DOM 2 (question about CSS)


    I am able to do this, to retrieve a value as a string:

    Code:
     //(IE version)
    
    document.styleSheets[0].rules.item(0).style.getPropertyValue('width');
    This will give me a string, e.g. '100px'

    But what I want is just the numeric value, i.e. 100, so that I can use it in a math formula.

    How can I do this?

    Thanks.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2003
    Posts
    1,014
    Rep Power
    15
    A simple
    parseInt(thewholelineyoualreadyhave)
    will do.

    Jeroen
  4. #3
  5. No Profile Picture
    CF sMod
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    Maine, USA (a.k.a. Boonies)
    Posts
    242
    Rep Power
    15
    You could make it Mozilla-compatible as well:

    var ss = document.styleSheets.item(0);
    var rules = ss.cssRules || ss.rules;
    var width = parseInt(rules.item(0).style.width);
  6. #4
  7. Über nübe
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Babylon 4
    Posts
    240
    Rep Power
    11
    Excellent! Thanks a lot!
    Hello, old friend...

IMN logo majestic logo threadwatch logo seochat tools logo