XML DOM replaceData() Method
Definition and Usage
The replaceData() method replaces data in the text node.
Syntax:
replaceData(start,length,string)
Parameters | Description |
---|---|
start | Required. Specifies where to replace characters. The starting value is 0. |
length | Required. Specifies how many characters to replace. |
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 replaces the first 8 characters of the text node of the <title> element with "Easy":
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.replaceData(0,8,"Easy");
document.write(x.nodeValue);
Output:
Easy Italian
Related Pages
XML DOM Reference Manual:CharacterData.replaceData()