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.

Figure 8–3. Writing some inline styles<br />

CHAPTER 8 ■ SCRIPTING CSS<br />

We replaced the blue sprite with the fuchsia one, slid the sprite to the left in order to reveal the down<br />

button, and moved the link entirely out of the container. It’s pretty draconian, but it illustrates the power<br />

of writing an element’s style member: scripted declarations in ElementCSSInlineStyle.style override<br />

those from anywhere else in the CSS cascade.<br />

One more thing: take another peek at ElementCSSInlineStyle.style for the Nike link. There’s<br />

something there other than one "" empty string after another now:<br />

var myStyle = document.getElementById("nike").style;<br />

myStyle.backgroundPosition;<br />

// "-99px -108px"<br />

myStyle.left;<br />

// "200px"<br />

So, our writing four CSS properties by way of ElementCSSInlineStyle.style was equivalent to doing<br />

so by way of the following markup:<br />

Nike<br />

In turn, this is why our scripted styles override those from elsewhere in the cascade, in other words,<br />

from eight.css.<br />

315

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

Saved successfully!

Ooh no, something went wrong!