By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

Turn CSS listing into JavaScript Array?

P: n/a
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
__________________________________
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


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/
Jul 23 '05 #2

P: n/a
cool I knew there was something like that just couldn't recall it. Thanks.

--
George Hester
__________________________________
"Martin Honnen" <ma*******@yahoo.de> wrote in message news:41***********************@newsread4.arcor-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/

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.