XML DOM createTextNode()Methods
Document object
Definition and Usage
The createTextNode() method creates a text node.
This method returns a Text object.
Syntax
createTextNode(text)
| Parameter | Description |
|---|---|
| text | A string that specifies the text of the node. |
Example
The following code snippet usesloadXMLDoc()put "books.xml"Load into xmlDoc, and add element nodes with text nodes to each <book> element:
Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("book");
for (i=0;i<x.length;i++)
{
newel=xmlDoc.createElement("edition");
newtext=xmlDoc.createTextNode("first");
newel.appendChild(newtext);
x[i].appendChild(newel);
}
//Output all title and edition
y=xmlDoc.getElementsByTagName("title");
z=xmlDoc.getElementsByTagName("edition");
for (i=0;i<y.length;i++)
{
document.write(y[i].childNodes[0].nodeValue);
document.write(" - Edition: ");
document.write(z[i].childNodes[0].nodeValue);
document.write("<br>");
}
Try it Yourself »
Document objectother extensions