XML DOM insertData() Method

Definition and Usage

The insertData() method inserts data into the text node.

Syntax:

insertData(start,string)
Parameters Description
start Required. Specifies where to insert characters. The starting value is 0.
string Required. Specifies the string to be inserted.

Example

In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().

The following code snippet inserts a string into the text node of the first <title> element in "books.xml":

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.insertData(0,"Cooking: ");
document.write(x.data);

Output:

Cooking: Everyday Italian

Related Pages

XML DOM Reference Manual:CharacterData.insertData()