795Chapter 26Style Sheet and (Crystaltech web hosting) Style ObjectsThe styleobject is
795Chapter 26Style Sheet and Style ObjectsThe styleobject is also a property of a rule/cssRuleobject. Thus, if you need to modifythe style of elements affected by an existing stylesheet rule, you approach the styleobjectthrough a different reference path, but the styleobject is treated just as it is for elements: document.styleSheets[0].rules[0].style.color = red ; // IE4+, MacIE5, Safaridocument.styleSheets[0].cssRules[0].style.color = red ; // MacIE5, NN6+/Moz, SafariMany scripters concern themselves solely with the styleobject, and at that, a styleobjectassociated with a particular element object. Rare are instances that require manipulation ofstyleSheetobjects beyond perhaps enabling and disabling them under script control. Therefore, if you are learning about these objects for the first time, pay closest attention tothe styleobject details rather than to the other related objects. Imported StylesheetsStylesheets embedded in a document via the styleelement can import additionalstylesheets via the @importselector: In this example scenario, the document sees just one styleSheetobject. But that object has a stylesheet nested inside the stylesheet defined by the external file. IE4+ calls one ofthese imported stylesheets an importobject. An importobject has all the properties of anystyleSheetobject, but its parentStyleproperty is a reference to the styleSheetthat owns the @importrule. In fact, the @importstatement does not even appear among therules collection of the IE styleSheetobject. Therefore, to access the first rule of theimported stylesheet, the reference is as the following: document.styleSheets[0].imports[0].rules[0] The W3C DOM and NN6+/Moz1+ treat importrule objects differently from the IE model. Tothe W3C DOM, even an at-rule is considered one of the cssRulescollection of a styleSheetobject. One of the properties of a cssRuleobject is type, which conveys an integer code valuerevealing whether the rule is a plain CSS rule or one of several other types, including an importrule. Of course, an imported rule object then has as one of its properties the styleSheetobject that, in turn, contains the rules defined in the external stylesheet file. The parent-childrelationship exists here, as well, whereby the stylesheet that contains the @importrule is ref- erenced by the imported styleSheetobject s parentStyleproperty (just as in IE4+). Reading Style PropertiesBoth the IE4+ and W3C object models exhibit a behavior that at first glance may seem discon- certing. On the one hand, the W3C and good HTML practice encourage defining styles remotely(that is, embedded via