Adding Nodes

The easiest way to learn about nodes is to start off by simply appending an element node (one which will contain a text node) to the end of your document. Scripts 11.1 (the HTML) and 11.2 allow the user to enter some data and click a button, and voila! a new paragraph is added to your page (Figure 11.2).

Figure 11.2. To add a node, enter the text in the field (top), and then click the button. The text appears on the page (bottom).

To add nodes:

1.
var newText = document.createTextNode (inText);
We start by creating a new text node (called newText) using the createTextNode() method, which will contain whatever text was found in ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.