HTML and CSS Reference
EXAMPLE 15.6 ( CONTINUED )
var divObj = document.getElementById("divtest");
divObj.innerHTML="Inserting new text in the
<div id="divtest" class="divStyle">
Original text in div container.
When the page has finished loading the statements in the anonymous function are
The variable, divObj , is assigned a reference to the div element identified by its id ,
By adding this alert , you will be able to see what was in the original div container be-
fore it is overwritten by the new text. After the user clicks the alert's OK button, the
new text will be displayed. If the alert box is removed, the original text will be over-
written before you can see it. The only output will be what you see in Figure 15.13.
The innerHTML property is used to change the text within the <div></div> tags.
The id and class attributes are assigned to the <div> tag.
Figure 15.13 The original text before it is modified.