XML DOM replaceData () method
Definition and Usage
replaceData () method replaces the data in a text node.
grammar
replaceData(start,length,string)
参数 | 描述 |
---|---|
start | 必需。规定在何处开始替换字符。开始值以 0 开始。 |
length | 必需。规定替换多少个字符。 |
string | 必需。规定插入的字符串。 |
In all instances, we use XML files books.xml and the JavaScript function loadXMLDoc () .
Examples
The following code fragment replaces the first <title> element with "Easy" text node of the first eight characters:
Examples
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.replaceData(0,8,"Easy");
document.write(x.nodeValue);
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
x.replaceData(0,8,"Easy");
document.write(x.nodeValue);
Output:
Easy Italian
try it"
Text objects