Java Reference
In-Depth Information
The DOM should not be confused with the browser object model (BOM) that was introduced in
Chapter 8. You'll see the differences between the two in detail shortly. For now, though, think of
the BOM as a browser‐dependent representation of every feature of the browser, from the browser
buttons, URL address line, and title bar to the browser window controls, as well as parts of the
web page, too. The DOM, however, deals only with the contents of the browser window or web
page (in other words, the HTML document). It makes the document available in such a way that
any browser can use exactly the same code to access and manipulate the content of the document.
To summarize, the BOM gives you access to the browser and some of the document, whereas the
DOM gives you access to all of the document, but only the document.
The great thing about the DOM is that it is browser‐ and platform‐independent. This means that
developers can write JavaScript code that dynamically updates the page, and that will work on any
DOM‐compliant browser without any tweaking. You should not need to code for different browsers
or take excessive care when coding.
The DOM achieves this independence by representing the contents of the page as a generic tree
structure. Whereas in the BOM you might expect to access something by looking up a property
relevant to that part of the browser and adjusting it, the DOM requires navigation through its
representation of the page through nodes and properties that are not specific to the browser. You
explore this structure a little later.
However, to use the DOM standard, ultimately developers require browsers that completely
implement the standard, something that no browser does 100 percent efficiently, unfortunately. To
make matters worse, no one browser implements the exact same DOM features that other browsers
support, but don't be scared off yet. All modern browsers support many of the same features
outlined by the DOM standard.
To provide a true perspective on how the DOM its in, we need to take a brief look at its relationship
with some of the other currently existing web standards. We should also talk about why there is
more than one version of the DOM standard, as well as different sections within the standard itself.
After understanding the relationships, you can look at using JavaScript to navigate the DOM and
to dynamically change a web page's content in more than one browser. The following items are on
your agenda:
The HTML and ECMAScript standards
The DOM standards
Manipulating the DOM
Writing cross‐browser JavaScript
Note Remember that the examples within this chapter are targeted only at
the DOM (with very few exceptions) and will be supported by modern brows-
ers (IE 9+, Chrome, Firefox, Opera, and Safari). Legacy browsers (IE8 and
below, earlier versions of Chrome, and similar early browsers) may or may not
support them.
Search WWH ::




Custom Search