18.04.2016 Views

Professional JavaScript For Web Developers

javascript for learners.

javascript for learners.

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.

Advanced DOM Techniques<br />

Although the basic DOM is pretty straightforward, you can manipulate a document’s underlying<br />

DOM tree in several ways. First, you can make use of several nonstandard properties and methods<br />

available in modern browsers, as well as little-known and underused DOM standard interfaces.<br />

This chapter highlights the browser features that make this possible. Some of the interfaces discussed<br />

in this chapter are defined by the DOM and some are not, but they all enhance your ability<br />

manipulate DOM documents and nodes.<br />

Scripting Styles<br />

When Cascading Style Sheets (CSS) were introduced 1996, they completely changed the way<br />

developers formatted their HTML pages. Instead of using HTML tags such as and ,<br />

pages began using CSS to define the appearance of fonts and other items. The natural next step for<br />

CSS support was to make styles accessible from <strong>JavaScript</strong>.<br />

Internet Explorer 4.0 introduced a style object for each element on a page to manage that element’s<br />

CSS-defined styles. The DOM eventually adopted this approach as a standard way to access an element’s<br />

style information.<br />

Today, the style object contains a property for each CSS style, albeit with some different formatting.<br />

All one-word CSS styles are represented by a property with the same name (for example, the<br />

color style is represented by style.color); two-word styles are represented by the first word<br />

followed by the capitalized second word with no dashes (for example, the background-color<br />

style is represented as style.backgroundColor). The following table lists some popular CSS<br />

attributes and their <strong>JavaScript</strong> style object equivalents:

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

Saved successfully!

Ooh no, something went wrong!