Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: Web
Expertise: Intermediate
Apr 27, 2000



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Changing Style Attributes Dynamically

Microsoft's IE4 supports the ability to change just about any CSS1 style attribute dynamically. To access an element's style, use the style object property that corresponds to the style attribute.

For example, to change the font-weight of a <P> element:

<P id = p1> This is my paragraph
your script would include the statement:
document.all.p1.style.fontWeight = "bold";

Don't know the name of the style property for the style attribute you want to change? The conversion is easy. Starting with the style attribute name, capitalize the first letter of any word after a hyphen, remove the hyphens, and you've got that attribute's style property. For example, the style property for the attribute background-color is backgroundColor and the style property for border-top-width is borderTopWidth.

Note: Although IE allows you to dynamically change the style object in a script block, Navigator does not.

Manoj K.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date