HTML and CSS Reference
var txt = document.createTextNode("Wow! Hope this works!");
< div id="divtest" class="divStyle">
<p>Original text in div container.</p>
After the page has completely loaded this anonymous function will be called.
A new paragraph is created with the DOM's createElement() method.
Now we get a reference to the div element defined on line 7.
The paragraph is appended to the div element with the DOM's appendChild()
method (see Figure 15.15).
The DOM's createTextNode() method will return a reference to the text that will be
placed within the new paragraph node.
The text created on line 5 is appended to the paragraph.
A div container is created with an id attribute, divtest , to be used on line 3 to get a
reference to the div element.
Figure 15.15 Creating a new p element with the DOM and appending it to a div