23.04.2013 Views

javascript

javascript

javascript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

CHAPTER 8 ■ SCRIPTING CSS<br />

316<br />

We’re good with querying CSS2Properties members. Now let’s take a peek at<br />

CSSStyleDeclaration.cssText. Clear both Firebug panels, but do not refresh Firefox. This leaves our<br />

scripted styles in place so cssText has something for us to read other than an "" empty string. Enter and<br />

run the following, verifying your work with Figure 8–4:<br />

myStyle.cssText;<br />

// "background-position: -99px -108px; background-image: url("images/fuchsia.gif"); left:<br />

200px; top: 30px;"<br />

Figure 8–4. Querying CSSStyleDeclaration.cssText<br />

cssText contains the CSS text of the style attribute. Imagine that. Now take a peek at cssText for the<br />

adidas link:<br />

document.getElementById("adidas").style.cssText;<br />

// ""<br />

It’s just a dull "" empty string. If you fully separate CSS from markup, reading cssText will be as<br />

mind-numbing as reading CSS2Properties members—unless you have a thing for "" empty strings. On<br />

the other hand, writing cssText provides a way to change several CSS properties in one fell swoop. Want<br />

to try doing that? Me too. Refresh Firefox, clear Firebug, and then enter and run the following sample.<br />

Note that the second statement wraps to two lines in this book but should be keyed in as one line in<br />

Firebug:

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

Saved successfully!

Ooh no, something went wrong!