XML DOM insertData() method
Definition and usage
The insertData() method inserts data into a 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 XML files 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()