Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML DOM replaceData() Method

XML DOM replaceData() Method


Text Object Reference Text Object


Definition and Usage

The replaceData() method replaces data in a text node.

Syntax

replaceData(start,length,string)

Parameters Description
start Required. Specifies where to start replacing characters. The starting value begins at 0.
length Required. Specifies how many characters to replace.
string Required. Specifies the string to insert.

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

Example

The following code snippet replaces the first 8 characters of the text node of the element with "Easy": </p>

Example

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];

x.replaceData(0,8,"Easy");

document.write(x.nodeValue);

Output:

Easy Italian

Try it »


Text Object Reference Text Object