Java Reference
In-Depth Information
Replacing Elements on a Page
The
replaceChild()
method can be used to replace one node with another. It is called
on the parent node and has two parameters: the new node and the node that is to be re-
placed. For example, if we wanted to change the content of the
<h1>
tag that makes the
title of the page, we could replace the text node with a new one, like so:
h1 = document.getElementById("title");
oldText = h1.firstChild;
newText = document.createTextNode("Iron Man Triathlon");
h1.replaceChild(newText,oldText)
Figure 6.9
shows that the text has now changed to "Iron Man Triathlon".