Turn CSS listing into JavaScript Array?

Discussion in 'Javascript' started by George Hester, Sep 11, 2004.

  1. I have this in a style sheet:

    div.track { font-family: Verdana, Arial, Helvetica, sans-serif; }

    In a JavaScript function I can pull out Verdana, Arial, Helvetica, sans-serif putting it
    into a JavaScript variable fontfamily.

    But what I would prefer is an array fontfamily[] where each font-family is an element
    of the array.

    I tried

    var fontfamily = new Array(getComputedStyleForElement(document.getElementById('divTrack'),'fontFamily'));

    but no dice. This is a one element Array with

    fontfamily[0] = Verdana, Arial, Helvetica, sans-serif

    What I was hoping for was:

    fontfamily[0] = Verdana
    fontfamily[1] = Arial
    fontfamily[2] = Helvetica
    fontfamily[3] = sans-serif

    Any neat ideas how I might do this?
    Thanks.

    --
    George Hester
    __________________________________
     
    George Hester, Sep 11, 2004
    #1
    1. Advertising

  2. George Hester wrote:

    > I have this in a style sheet:
    >
    > div.track { font-family: Verdana, Arial, Helvetica, sans-serif; }
    >
    > In a JavaScript function I can pull out Verdana, Arial, Helvetica, sans-serif putting it
    > into a JavaScript variable fontfamily.
    >
    > But what I would prefer is an array fontfamily[] where each font-family is an element
    > of the array.


    If you have a string you can split it into an array e.g.

    var fonts = 'Verdana, Arial, Helvetica, sans-serif';
    var fontsArray = fonts.split(/, /g);

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Sep 11, 2004
    #2
    1. Advertising

  3. cool I knew there was something like that just couldn't recall it. Thanks.

    --
    George Hester
    __________________________________
    "Martin Honnen" <> wrote in message news:41432321$0$26104$-online.net...
    >
    >
    > George Hester wrote:
    >
    > > I have this in a style sheet:
    > >
    > > div.track { font-family: Verdana, Arial, Helvetica, sans-serif; }
    > >
    > > In a JavaScript function I can pull out Verdana, Arial, Helvetica, sans-serif putting it
    > > into a JavaScript variable fontfamily.
    > >
    > > But what I would prefer is an array fontfamily[] where each font-family is an element
    > > of the array.

    >
    > If you have a string you can split it into an array e.g.
    >
    > var fonts = 'Verdana, Arial, Helvetica, sans-serif';
    > var fontsArray = fonts.split(/, /g);
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
     
    George Hester, Sep 11, 2004
    #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. Vasilis Serghi

    How can i read a directory listing into an array

    Vasilis Serghi, Feb 9, 2004, in forum: C Programming
    Replies:
    1
    Views:
    365
    Joona I Palaste
    Feb 9, 2004
  2. Replies:
    0
    Views:
    267
  3. WOSG Services
    Replies:
    0
    Views:
    170
    WOSG Services
    Jun 30, 2008
  4. Eric Osman
    Replies:
    2
    Views:
    355
    Eric Osman
    Apr 14, 2004
  5. seektime
    Replies:
    23
    Views:
    398
    Prasad, Ramit
    Oct 25, 2012
Loading...

Share This Page