Turn CSS listing into JavaScript Array?

G

George Hester

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.
 
M

Martin Honnen

George said:
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);
 
G

George Hester

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

--
George Hester
__________________________________
Martin Honnen said:
George said:
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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top