Java Reference
In-Depth Information
var anotherPara = createElement("p","Transition 2");
This means that we can now create new elements in a single line of code rather than three.
It's time to add these new elements to our example page.
Adding Elements to the Page
We have already seen the
appendChild()
method. This can be called on a node to add
a new child node. The new node will always be added at the end of the list of child nodes.
The following example will add the
newPara
paragraph element we created above to the
sports.appendChild(newPara);
<< <p>
