473,508 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamically apply a font family

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
10 1972
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
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
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
-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
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
-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
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
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
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
-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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5160
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
3
31794
by: Dave | last post by:
How do I apply a font name to an entire HTML table without specifying it in each cell/row, or applying a CSS ID to each cell or row? -- - Dave
3
3384
by: mike | last post by:
I have a script that is not rendering the textwrap in svg properly. //does not work ..... var svgLand = svgObj.getElementById("NarrDisplay"); mytextwrap=...
3
2006
by: spolsky | last post by:
hi, it is possible to apply multiple styles as shown in the following example. <STYLE TYPE="text/css"><!-- BODY { background-color:salmon; } P { margin-left:20px; } .clsCode {...
2
1622
by: strauchdieb | last post by:
hey everyone i try to figure out how to calculate string width in a textarea while typing in it. the textarea has a fixed start width. when the string gets longer as the textarea width, the...
0
1560
by: uncensored | last post by:
Hi, Sort of new with the whole treeview control and I was wondering is there a way to build a treeview menu using my SQL data I pull from a database instead of having to hard code it into the...
4
1960
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
2
3616
by: kheitmann | last post by:
OK, so I have a blog. I downloaded the "theme" from somewhere and have edited a few areas to suit my needs. There are different font themes within the page theme. Long story short, my "Text Posts"...
0
7133
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7405
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7066
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.