CSS and JavaScript

N

NEWS

if I am trying to change font in an input TEXT box using JavaScript how do I
do it?


document.forms[x].elements[y].class=fontSize;

fontSize being a CSS class, works if I hard code it in but will not work
dynamicly as above
 
V

VK

tag attribute is called "class"
the relevant scriptable property is called className. They have to do
it because "class" is a reserved name in script, so could screw the
things up.

Another discrepancy of the same kind and for the same reason:
<label for="b01">
but
labelObject.htmlFor

Also className takes string argument, not an object.

Also "fontSize" is equal to the camelized form of "font-size" style
attribute wich will hit your code somewhere sooner or later.

Puting all together:

document.forms[x].elements[y].className = "specialFontSize";
 
W

web.dev

NEWS said:
if I am trying to change font in an input TEXT box using JavaScript how do I
do it?


document.forms[x].elements[y].class=fontSize;

fontSize being a CSS class, works if I hard code it in but will not work
dynamicly as above

There is an ambiguous messages I'm getting from this, so I'll just
cover them all.

1. Are you just trying to change the element's class? In that case:

document.forms["x"].elements["y"].className = "fontSize";

2. There is a font-size property in css, and if that's all you want to
affect then:

document.forms["x"].elements["y"].style.fontSize = "12pt";
 
N

NEWS

web.dev said:
if I am trying to change font in an input TEXT box using JavaScript how
do I
do it?


document.forms[x].elements[y].class=fontSize;

fontSize being a CSS class, works if I hard code it in but will not work
dynamicly as above

There is an ambiguous messages I'm getting from this, so I'll just
cover them all.

1. Are you just trying to change the element's class? In that case:

document.forms["x"].elements["y"].className = "fontSize";

2. There is a font-size property in css, and if that's all you want to
affect then:

document.forms["x"].elements["y"].style.fontSize = "12pt";

I would like to do both, meaning CSS class changing from fontSize to
NoStyle; and I did not know about the second option you showed me.

Thanks
 
N

NEWS

VK said:
tag attribute is called "class"
the relevant scriptable property is called className. They have to do
it because "class" is a reserved name in script, so could screw the
things up.

Another discrepancy of the same kind and for the same reason:
<label for="b01">
but
labelObject.htmlFor

Also className takes string argument, not an object.

Also "fontSize" is equal to the camelized form of "font-size" style
attribute wich will hit your code somewhere sooner or later.

Puting all together:

document.forms[x].elements[y].className = "specialFontSize";

Is there a book that you would recommend I study to know this stuff. I have
been looking but many of the books seem so huge it would take a life time to
find what I need to learn
 
R

Randy Webb

NEWS said the following on 12/21/2005 6:42 PM:
So what do you use? URL, NEWS GROUPS???

You can learn more from reading the FAQ URL above and searching the
archives of this newsgroup (comp.lang.javascript) than you could ever
hope to learn from a book.
 
R

RobG

NEWS said:
news:[email protected]... [...]
2. There is a font-size property in css, and if that's all you want to
affect then:

document.forms["x"].elements["y"].style.fontSize = "12pt";


I would like to do both, meaning CSS class changing from fontSize to
NoStyle; and I did not know about the second option you showed me.

Since we're talking CSS, relative font sizes are preferred: use % or em
rather than pt or px.

Changing the value of a property of the element's style object (as
suggested by webdev) can have different results to modifying those same
properties via changing the element's class - the 'cascade' part of CSS
and specificity (I think I spelled that right!).
 
R

Randy Webb

Good Man said the following on 12/22/2005 1:06 AM:
I disagree. The latest version of The Javascript Bible is fantastic.

You are welcome to disagree. It is your free choice. And your opinion
may be that the Bible is fantastic but most of the people in this group
who have read it or reviewed it don't agree with you, myself included.

http://jibbering.com/faq/#FAQ3_1

There is a very good reason why that section does not refer to the
Javascript Bible. And yes, I have TJB on my desk. It is *not* a good
book for learning from.
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top