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.

440<br />

ruleObject.style<br />

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

cssRule and rule Objects<br />

Properties<br />

selectorText<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 examine the<br />

selectorText property of rules in the first styleSheet object of the page. Enter<br />

each of the following statements in the top text box:<br />

document.styleSheets[0].rules[0].selectorText<br />

document.styleSheets[0].rules[1].selectorText<br />

Compare these values against the source code view for the STYLE element in the<br />

page.<br />

style<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 modify a style property<br />

of one of the styleSheet rules in the page. The syntax shown here is for IE4+,<br />

but you can substitute the cssRules reference for the rules collection reference in<br />

NN6 (and IE5/Mac) if you like.<br />

Begin by reloading the page and making sure the style sheet is enabled. Enter the<br />

following statement into the top text box:<br />

document.styleSheets[0].disabled = false<br />

The first rule is for the myP element on the page. Change the rule’s font-size<br />

style:<br />

document.styleSheets[0].rules[0].style.fontSize = “20pt”<br />

Look over the style object properties in the discussion of the style object<br />

later in this chapter and have fun experimenting with different style properties.<br />

After you are finished, reload the page to restore the styles to their default states.<br />

✦ ✦ ✦

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

Saved successfully!

Ooh no, something went wrong!