JavaScript Style Sheet Syntax

So far throughout this chapter, all style sheet examples have used the CSS syntax promoted in the W3C recommendations and implemented to varying degrees in both Navigator 4 and Internet Explorer 4. In this section, we discuss Netscape’s alternative syntax for specifying style sheets. This syntax follows the rules of the JavaScript (and, by extension, ECMAScript) language, but the object model is unique to Navigator 4. Unless you exercise browser branching safeguards, you will encounter script errors if you attempt to load documents equipped with this style sheet syntax into Internet Explorer 4. It’s important to emphasize that this is not an alternate style sheet mechanism; rather, it is just another way to program CSS style sheets. The advantage of this syntax is that you gain the power of using other JavaScript statements inside <STYLE> tags to create, for example, algorithmically derived values for style sheet rules.[1]

As you may have noticed in Table 3.1, not every CSS attribute implemented in Navigator 4 has a JavaScript equivalent. The most common attributes are accounted for, but some design choices, such as setting independent colors for border sides, aren’t available in Navigator 4—in JavaScript or CSS syntax.

Attributes and Elements

JavaScript syntax simplifies assigning values to style attributes and then assigning those attributes to HTML elements, in that you don’t have to learn the CSS syntax. Each statement in a JavaScript style sheet ...

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.