HTML and CSS Reference
use your code to experiment with the various methods listed in Table 1-2 in this function,
starting with getElementById .
The getElementById method returns the element in the page that matches the specific ID
value you pass to it. It returns null if no element on the page has the specified ID. Each ele-
ment on the page should have a unique ID. For example, if you want to reference the <div>
element with the ID outerDiv , you would use the following code:
var element = document.getElementById("outerDiv");
you have actually accessed the DOM successfully. The alert isn't all that useful in the real
world but it is for development purposes. When you run the page, notice the message box
from the browser with all the innerHTML contents of the <div> you selected out of the DOM
with your code (see Figure 1-14).