204
Chapter 4
Meet the DOM
Although you may not have realized it, you’ve been using the DOM
since way back in Chapter 1. Remember this code from Katie’s
Boards ‘R’ Us report?
(again)
function updatePage() {
var newTotal = request.responseText;
var boardsSoldEl = document.getElementById(“boards-sold”);
var cashEl = document.getElementById(“cash”);
...
}
function getCustomerInfo() {
var phone =
document.getElementById(“phone”).value;
var url = “lookupCustomer.php?phone=” +
escape(phone);
request.open(“GET”, url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
And here’s some similar code from the Break Neck pizza app:
The document object gives
JavaScript access to the DOM tree
that the web browser creates.
Here’s that
document
object again.
The “document”
object gives
your JavaScript
access to the
web browser’s
DOM tree.
Don’t miss this... it’s
probably the most important
thing in the whole chapter!
a dom retrospective
We’ve left out the rest of the
code from this function.