15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

436<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

The syntax in the demonstration is for NN6 and IE5/Mac, but referencing the<br />

cssRules property provides the same access for the IE4+ object model.<br />

styleSheet Object<br />

Properties<br />

cssRules<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ (✓) (✓)<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to look at the cssRules<br />

property in NN6+ or IE5+/Mac. First, view how many rules are in the first styleSheet<br />

object of the page by entering the following statement into the top text box:<br />

document.styleSheets[0].cssRules.length<br />

Now use the array with an index value to access one of the rule objects to view<br />

the rule object’s properties list. Enter the following statement into the bottom text<br />

box:<br />

document.styleSheets[0].cssRules[1]<br />

You use this syntax to modify the style details of an individual rule belonging to<br />

the styleSheet object.<br />

cssText<br />

styleSheetObject.cssText<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓<br />

Example<br />

Use The Evaluator (Chapter 13) to replace the style rules in one blast via the<br />

cssText property. Begin by examining the value returned from the property for the<br />

initially disabled style sheet by entering the following statement into the top text<br />

box:<br />

document.styleSheets[0].cssText<br />

Next, enable the style sheet so that its rules are applied to the document:<br />

document.styleSheets[0].disabled = false

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

Saved successfully!

Ooh no, something went wrong!