15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Style Sheet<br />

Objects<br />

(Chapter 30)<br />

<strong>Examples</strong> in this chapter focus on the properties and<br />

methods of the styleSheet object. As described in<br />

Chapter 30 of the <strong>JavaScript</strong> <strong>Bible</strong>, object models that support<br />

scriptable style sheets define both the STYLE element object<br />

(representing the element created with a tag pair)<br />

and the more abstract styleSheet object. The latter may be<br />

created by virtue of a STYLE element or perhaps imported<br />

from an external style sheet definition file.<br />

Use the styleSheet object to gain access to the details of<br />

the rules defined for a given style sheet. Methods of the<br />

styleSheet object (different syntax for IE4+ and W3C object<br />

models) allow dynamic creation or deletion of rules within a<br />

style sheet. Properties of the styleSheet object (again, different<br />

syntax) return arrays of objects representing the style<br />

rules contained by the style sheet. The rule objects themselves<br />

have properties allowing reading and writing of rule<br />

selectors and even individual style attributes within that rule<br />

(since a single rule can list multiple style attributes).<br />

<strong>Examples</strong> Highlights<br />

✦ Compare examples for the styleSheet.cssRules and<br />

styleSheet.rules properties to see how different<br />

browsers provide access to arrays of rule objects.<br />

✦ You can observe in The Evaluator (Chapter 13 in the<br />

<strong>JavaScript</strong> <strong>Bible</strong>) how the styleSheet.disabled property<br />

can switch a style sheet on and off dynamically.<br />

✦ Compare the styleSheet object method pairs for<br />

inserting and deleting rules to an existing style sheet.<br />

The walk-through examples let you follow the same<br />

steps for both the IE4+ and NN6 syntaxes.<br />

✦ The final example in this chapter demonstrates how<br />

scripts can modify a single attribute of a style sheet rule.<br />

14<br />

C H A P T E R<br />

✦ ✦ ✦ ✦<br />

In This Chapter<br />

Enabling and<br />

disabling entire style<br />

sheets<br />

Accessing an<br />

individual style rule<br />

from a style sheet<br />

Adding and deleting<br />

style sheet rules<br />

✦ ✦ ✦ ✦

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!