799Chapter 26Style Sheet and Style ObjectsPropertiescssRulesValue:Array of rule (Web server version)

799Chapter 26Style Sheet and Style ObjectsPropertiescssRulesValue:Array of rule objects.Read-OnlyCompatibility:WinIE-, MacIE5, NN6+, Moz1+, Safari1+ The cssRulesproperty returns an array of stylesheet rule objects. Strictly speaking, theobjects are called cssRuleobjects in the W3C DOM terminology. This property is implementedin MacIE5, but not in the Windows version as of IE6. The list of rule objects is in source codeorder. The corresponding WinIE4+ property is rules. ExampleUse The Evaluator (Chapter 13) to look at the cssRulesproperty in W3C DOM browsers orMacIE5. First, view how many rules are in the first styleSheetobject of the page by enteringthe following statement into the top text box: document.styleSheets[0].cssRules.lengthNow use the array with an index value to access one of the rule objects to view the ruleobject s properties list. Enter the following statement into the bottom text box: document.styleSheets[0].cssRules[1] You use this syntax to modify the style details of an individual rule belonging to thestyleSheetobject. Related Items:rulesproperty, cssRule, ruleobjects. cssTextValue:String.Read/WriteCompatibility:WinIE5+, MacIE5, NN-, Moz-, Safari- The cssTextproperty contains a string of all stylesheet rules contained by the styleSheetobject. Parsing this text in search of particular strings is not wise because the text returnedby this property can have carriage returns and other formatting that is not obvious from thetext that is assigned to the rules in the stylesheet. But you can use this property as a way tocompletely rewrite the rules of a stylesheet in a rather brute-force manner: Assemble a stringconsisting of all the new rules and assign that string to the cssTextproperty. The more for- mal way of modifying rules (adding and removing them) is perhaps better form, but there isno penalty for using the cssTextproperty if your audience is strictly IE5+. ExampleUse The Evaluator (Chapter 13) to replace the style rules in one blast via the cssTextproperty. Begin by examining the value returned from the property for the initially disabled stylesheetby entering the following statement into the top text box: document.styleSheets[0].cssTextNext, enable the stylesheet so that its rules are applied to the document: document.styleSheets[0].disabled = falseFinally, enter the following statement into the top text box to overwrite the stylesheet withentirely new rules. document.styleSheets[0].cssText = p {color:red} styleSheetObject.cssText
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply