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

dynamically apply a font family

P: n/a
How do you apply a CSS font-family (say, Times, "New Century
Schoolbook", serif) to an object? This

obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";

seems to ignore everything after Times.

Andrew Poulos
Jun 16 '07 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Andrew Poulos wrote:
How do you apply a CSS font-family (say, Times, "New Century
Schoolbook", serif) to an object? This

obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";

seems to ignore everything after Times.
>
Well, it should, if "Times" is available.
Mick
Jun 17 '07 #2

P: n/a
Michael White wrote:
Andrew Poulos wrote:
>How do you apply a CSS font-family (say, Times, "New Century
Schoolbook", serif) to an object? This

obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";


seems to ignore everything after Times.
>>
Well, it should, if "Times" is available.
Sorry, what I meant is that if the first font is unavailable then it
doesn't try any of the other fonts. It seems to only work with font
families that only consist of a single font name.

Andrew Poylos
Jun 17 '07 #3

P: n/a
Andrew Poulos wrote:
Michael White wrote:
>Andrew Poulos wrote:
>>How do you apply a CSS font-family (say, Times, "New Century
Schoolbook", serif) to an object? This

obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";


seems to ignore everything after Times.
>>>
Well, it should, if "Times" is available.

Sorry, what I meant is that if the first font is unavailable then it
doesn't try any of the other fonts. It seems to only work with font
families that only consist of a single font name.
Hrmm... I see you are doing it the "CSS way." Did you try:

obj.style.fontFamily = "Times, New Century Schoolbook, serif"; ?
Andrew Poylos
If you have forgotten how to spell your own name I think you need to
back away from the computer for a while. ;)

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 17 '07 #4

P: n/a
-Lost wrote:
Andrew Poulos wrote:
>Michael White wrote:
>>Andrew Poulos wrote:
How do you apply a CSS font-family (say, Times, "New Century
Schoolbook", serif) to an object? This

obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";

seems to ignore everything after Times.

Well, it should, if "Times" is available.

Sorry, what I meant is that if the first font is unavailable then it
doesn't try any of the other fonts. It seems to only work with font
families that only consist of a single font name.

Hrmm... I see you are doing it the "CSS way." Did you try:

obj.style.fontFamily = "Times, New Century Schoolbook, serif"; ?
I couldn't get it to work so I gave up and set a class instead.

Andrew Poulos
Jun 17 '07 #5

P: n/a
Andrew Poulos wrote:
-Lost wrote:
>Andrew Poulos wrote:
>>Michael White wrote:
Andrew Poulos wrote:
How do you apply a CSS font-family (say, Times, "New Century
Schoolbook", serif) to an object? This
>
obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";
>
>

seems to ignore everything after Times.
>
Well, it should, if "Times" is available.

Sorry, what I meant is that if the first font is unavailable then it
doesn't try any of the other fonts. It seems to only work with font
families that only consist of a single font name.

Hrmm... I see you are doing it the "CSS way." Did you try:

obj.style.fontFamily = "Times, New Century Schoolbook, serif"; ?

I couldn't get it to work so I gave up and set a class instead.
Um... OK. It *does* work though. Setting a class is more robust
anyway, though.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 17 '07 #6

P: n/a
-Lost wrote:
Andrew Poulos wrote:
>-Lost wrote:
>>Andrew Poulos wrote:
Michael White wrote:
Andrew Poulos wrote:
>How do you apply a CSS font-family (say, Times, "New Century
>Schoolbook", serif) to an object? This
>>
>obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";
>>
>>
>
seems to ignore everything after Times.
>>
Well, it should, if "Times" is available.

Sorry, what I meant is that if the first font is unavailable then it
doesn't try any of the other fonts. It seems to only work with font
families that only consist of a single font name.

Hrmm... I see you are doing it the "CSS way." Did you try:

obj.style.fontFamily = "Times, New Century Schoolbook, serif"; ?

I couldn't get it to work so I gave up and set a class instead.

Um... OK. It *does* work though. Setting a class is more robust
anyway, though.
I tested it again (with FF 2 and IE 6) and multi-word font names get
ignored if I do either:
obj.style.fontFamily = "Timeees, 'New Century Schoolbook', serif";
or
obj.style.fontFamily = "Timeees, New Century Schoolbook, serif";

I named the first font intentionally wrong to see if 'New Century
Schoolbook' appears, and it doesn't. I get the default serif font.

Andrew Poulos
Jun 17 '07 #7

P: n/a
Andrew Poulos wrote:
I tested it again (with FF 2 and IE 6) and multi-word font names get
ignored if I do either:
obj.style.fontFamily = "Timeees, 'New Century Schoolbook', serif";
or
obj.style.fontFamily = "Timeees, New Century Schoolbook, serif";

I named the first font intentionally wrong to see if 'New Century
Schoolbook' appears, and it doesn't. I get the default serif font.
Are you sure that the 'New Century Schoolbook' font is installed on your
computer? Without JS, does setting the style of an element to New Century
Schoolbook work?

I tried using JS to swap between the two list of font families:

"Pizza, 'New Century Schoolbook', 'Times New Roman', serif"
- and -
"Pizza, 'Comic Sans MS', 'New Century Schoolbook', Arial, serif"

When setting the element's fontFamily property to the top line above, I
would get Times New Roman and when setting it to the bottom line above, I
would get Comic Sans. I tried this in both Firefox 2 and IE7 with the same
results.

Ben
Jun 17 '07 #8

P: n/a
Ben Amada wrote:
Andrew Poulos wrote:
>I tested it again (with FF 2 and IE 6) and multi-word font names get
ignored if I do either:
obj.style.fontFamily = "Timeees, 'New Century Schoolbook', serif";
or
obj.style.fontFamily = "Timeees, New Century Schoolbook, serif";

I named the first font intentionally wrong to see if 'New Century
Schoolbook' appears, and it doesn't. I get the default serif font.

Are you sure that the 'New Century Schoolbook' font is installed on your
computer? Without JS, does setting the style of an element to New Century
Schoolbook work?

I tried using JS to swap between the two list of font families:

"Pizza, 'New Century Schoolbook', 'Times New Roman', serif"
- and -
"Pizza, 'Comic Sans MS', 'New Century Schoolbook', Arial, serif"

When setting the element's fontFamily property to the top line above, I
would get Times New Roman and when setting it to the bottom line above, I
would get Comic Sans. I tried this in both Firefox 2 and IE7 with the same
results.
Yeah, it does work. I would still omit trying to inner quote it.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 17 '07 #9

P: n/a
Andrew Poulos wrote:
-Lost wrote:
>Andrew Poulos wrote:
>>-Lost wrote:
Andrew Poulos wrote:
Michael White wrote:
>Andrew Poulos wrote:
>>How do you apply a CSS font-family (say, Times, "New Century
>>Schoolbook", serif) to an object? This
>>>
>>obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";
>>>
>>>
>>
> seems to ignore everything after Times.
>>>
> Well, it should, if "Times" is available.
>
Sorry, what I meant is that if the first font is unavailable then
it doesn't try any of the other fonts. It seems to only work with
font families that only consist of a single font name.

Hrmm... I see you are doing it the "CSS way." Did you try:

obj.style.fontFamily = "Times, New Century Schoolbook, serif"; ?

I couldn't get it to work so I gave up and set a class instead.

Um... OK. It *does* work though. Setting a class is more robust
anyway, though.
I tested it again (with FF 2 and IE 6) and multi-word font names get
ignored if I do either:
obj.style.fontFamily = "Timeees, 'New Century Schoolbook', serif";
or
obj.style.fontFamily = "Timeees, New Century Schoolbook, serif";

I named the first font intentionally wrong to see if 'New Century
Schoolbook' appears, and it doesn't. I get the default serif font.
Then I would have to guess that font does not exist on your system.
There is one known, it *DOES* work, so your error obviously lies
elsewhere (like perhaps, you not specifying the font name correctly).

I often find it funny (or sad) when people say, "Oh, I couldn't get it
to work." and then dismiss it. I would be more concerned about why
something so simple doesn't work.

I mean, you're not using Lynx to run this script are you?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 17 '07 #10

P: n/a
-Lost wrote:
Andrew Poulos wrote:
>-Lost wrote:
>>Andrew Poulos wrote:
-Lost wrote:
Andrew Poulos wrote:
>Michael White wrote:
>>Andrew Poulos wrote:
>>>How do you apply a CSS font-family (say, Times, "New Century
>>>Schoolbook", serif) to an object? This
>>>>
>>>obj.style.fontFamily = "Times, 'New Century Schoolbook', serif";
>>>>
>>>>
>>>
>> seems to ignore everything after Times.
>>>>
>> Well, it should, if "Times" is available.
>>
>Sorry, what I meant is that if the first font is unavailable then
>it doesn't try any of the other fonts. It seems to only work with
>font families that only consist of a single font name.
>
Hrmm... I see you are doing it the "CSS way." Did you try:
>
obj.style.fontFamily = "Times, New Century Schoolbook, serif"; ?

I couldn't get it to work so I gave up and set a class instead.

Um... OK. It *does* work though. Setting a class is more robust
anyway, though.
I tested it again (with FF 2 and IE 6) and multi-word font names get
ignored if I do either:
obj.style.fontFamily = "Timeees, 'New Century Schoolbook', serif";
or
obj.style.fontFamily = "Timeees, New Century Schoolbook, serif";

I named the first font intentionally wrong to see if 'New Century
Schoolbook' appears, and it doesn't. I get the default serif font.

Then I would have to guess that font does not exist on your system.
There is one known, it *DOES* work, so your error obviously lies
elsewhere (like perhaps, you not specifying the font name correctly).
You're right it does work without the single quotes. I was working on a
different computer and stupidly didn't check the installed fonts.

Andrew Poulos
Jun 18 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.