TOC PREV NEXT INDEX

Put your logo here!


DOM Style Reference


To ADD: using element.setAttribute("style", "background-color: blue;") will remove any existing style properties on the element, so it's considered dangerous.

This chapter describes the style objects and the various interfaces they make available for manipulating style rules for HTML and XML documents. The final section, DOM CSS Properties List, is a list of the style properties that can be set or returned with the element.style property.

· DOM Style Object
· DOM styleSheet Object
· DOM cssRule Object
· DOM CSS Properties List

The basic style object exposes the StyleSheet and the CSSStyleSheet interfaces from the DOM Level 2 Events specification. Those interfaces contain members like insertRule, selectorText, and parentStyleSheet for accessing and manipulating the individual style rules that make up a CSS stylesheet.

To get to the style objects from the document, you can use the document.stylesheets property and access the individual objects by index (e.g., document.stylesheets[0] is the first stylesheet defined for the document, etc.). Though there are various syntaxes for expressing stylesheets for a document, Netscape supports CSS exclusively, so the style object retrieved from this array implements both the StyleSheet and CSSStyleSheet interfaces.

ss = document.styleSheets[1]; 
ss.cssRules[0].style.backgroundColor="blue"; 

The list of properties available in the DOM from the style property is given in the DOM CSS Properties List section below.


mozilla.org | mailto:oeschger | bug 93108
TOC PREV NEXT INDEX