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

element:

 

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.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: