Extract elements from string in javascript

Discussion in 'JavaScript' started by ruby, Jun 15, 2008.

  1. #1
    Hi all... I need someone to write a regular expression or some code to extract elements from this string:

    .at_1272 { width:325px; height:100px; background-color: none; padding: 3px; }


    I want to extract the values of width and height.

    So width=325px and height=100px

    I need them in two javascript variables.

    If someone can write that I'd appreciate!
     
    ruby, Jun 15, 2008 IP
  2. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't you a thread about something similar? Why don't you just continue in that thread?
     
    MMJ, Jun 15, 2008 IP
  3. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #3
    No its something completely different...
     
    ruby, Jun 15, 2008 IP
  4. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #4
    why dont you just use...

    var width = document.getElementsByClassName.style.width;
    var height = document.getElementsByClassName.style.height;

    ??
     
    crath, Jun 15, 2008 IP
  5. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #5
    ahhh yes... silly me. Cheers. Ill try it with what I am doing.
     
    ruby, Jun 15, 2008 IP
  6. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #6
    can you please tell me if that worked out for you? i am curious myself :)
     
    crath, Jun 15, 2008 IP
  7. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #7
    Well Ive had no luck.... how can I use:

    var width = document.getElementsByClassName.style.width;
    var height = document.getElementsByClassName.style.height;

    To get those values?

    Ive tried:

    document.getElementsByClassName['at_1272'].style.width;

    But it doesnt work.
     
    ruby, Jun 15, 2008 IP
  8. crath

    crath Well-Known Member

    Messages:
    661
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    100
    #8
    can you please link to your page?
     
    crath, Jun 15, 2008 IP
  9. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #9
    Well no I cant I am in a dev environment locally.

    When I use that notation I get: document.getElementsByClassName has no properties
     
    ruby, Jun 15, 2008 IP
  10. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #10
    Surely someone has had to do this in the past?
     
    ruby, Jun 15, 2008 IP
  11. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #11
    ruby, Jun 15, 2008 IP
  12. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #12
    document.getElementsByClassName Isn't implemented yet except for in a few browsers.

    Use something like: document.getElementById('id').style.width;
     
    MMJ, Jun 16, 2008 IP
  13. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #13
    parseInt(document.getElementById('id').style.width);
    might work
     
    sharry, Jun 16, 2008 IP