Changing Style Attribute Values

The lack of automatic content reflow in Navigator 4 prevents it from displaying most changes to style sheet attribute values after the document has loaded, even if the values are exposed to scripting. By contrast, the list of read-write properties associated with IE 4’s style object (see Chapter 9) is impressive, to say the least. If the conditions of your design are just right, however, you might be able to get away with a cross-platform workaround for the desired style changes. The tactic is to consider the Navigator 4 methodologies as the lowest common denominator: if the trick can be done in Navigator 4, it can be done cross-platform, even if not in the most elegant or efficient way for IE 4.

We’ll examine both an IE 4-specific and a cross-platform way of cycling a chunk of text through a sequence of colors. For IE 4, the job is as simple as changing the color attribute of a SPAN element’s style. For Navigator 4 compatibility, however, each color version of the text must be created as a separate positioned element that is shown and hidden in the appropriate order.

Example 5.9 shows the Internet Explorer 4 version. A single SPAN element in the body has the color property of its style changed in a for loop. For programming convenience, the color names are stored in a global variable array, with another global variable maintaining a record of the color currently showing. No positioning or other tactics are required.

Example 5-9. Internet Explorer ...

Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.