XML DOM insertData()Methods


Comment object

Definition and Usage

The insertData() method inserts data into a comment node.

Syntax

commentNode.insertData(start,string)

Parameter Description
start Required. Specifies where to start inserting characters. The start value begins at 0.
string Required. Specifies the string to be inserted.


Example

The following code snippet usesloadXMLDoc()put "books_comment.xmlLoad into xmlDoc and insert a string into the first comment node:

Example

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 Yourself »

In the above example, we use a loop and an if statement to perform processing only for comment nodes. The node type of a comment node is 8.


Comment objectother extensions