Latest web development tutorials

XML DOM insertData () method

Comment Object Reference Comment objects

Definition and Usage

insertData () method to insert data into a comment node.

grammar

commentNode.insertData(start,string)

参数 描述
start 必需。规定在何处开始插入字符。开始值以 0 开始。
string 必需。规定要插入的字符串。


Examples

The following code fragment uses loadXMLDoc () to " books_comment.xml " into xmlDoc to insert a comment node first string:

Examples

xmlDoc=loadXMLDoc("books_comment.xml");

x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
x[i].insertData(25,"Italian ");
document.write(x[i].data);
document.write("
");
}
}

Output:

125 Simple and Delicious Italian Recipes (Hardcover)

try it"

In the example above, we use some loops and if statements to execute only the processing nodes for comment. Node type comment node is eight.


Comment Object Reference Comment objects