Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The crux of DHTML is its ability to use JavaScript to dynamically change the style attributes applied to individual elements within a document. The DOM Level 2 standard defines an API that makes this quite easy to do. In Chapter 15, you saw how to use the DOM API to obtain references to document elements either by tag name or ID, or by recursively traversing the entire document. Once you obtain a reference to the element whose styles you want to manipulate, you use the element's style property to obtain a CSS2Properties object for that document element. This JavaScript object has properties corresponding to each CSS1 and CSS2 style attribute. Setting these properties has the same effect as setting the corresponding styles in a style attribute on the element. Reading these properties returns the CSS attribute value, if any, that was set in the style attribute of the element. The CSS2Properties object is documented in Part IV.
It is important to understand that the CSS2Properties object you obtain with the style property of an element specifies only the inline styles of the element. You cannot use the properties of the CSS2Properties object to obtain information about the stylesheet styles that apply to the element. By setting properties on this object, you are defining inline styles that effectively override stylesheet styles.