Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Turn CSS listing into JavaScript Array?

Reply
Thread Tools

Turn CSS listing into JavaScript Array?

 
 
George Hester
Guest
Posts: n/a
 
      09-11-2004
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.getEleme ntById('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
__________________________________
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      09-11-2004


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/
 
Reply With Quote
 
 
 
 
George Hester
Guest
Posts: n/a
 
      09-11-2004
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$...
>
>
> 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/

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An easy and affordable way to turn your web design to qualityXHTML/CSS/JS WOSG Services Ruby 0 06-30-2008 11:31 AM
Recursively listing files into directories Alain.Feler Ruby 3 05-15-2005 06:09 PM
turn quotes into &quot; and apostrophes into &apos; Eric Osman Javascript 2 04-14-2004 03:51 PM
CSS Property changes via Javascript trashes CSS print version Julie Siebel Javascript 4 02-25-2004 01:29 PM
How can i read a directory listing into an array Vasilis Serghi C Programming 1 02-09-2004 07:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57