XML DOM appendData()Methods
Comment object
Definition and Usage
The appendData() method adds data to the end of a comment node.
Syntax
commentNode.appedData(string)
| Parameter | Description |
|---|---|
| string | Required. A string to add to the comment node. |
Example
The code snippet below usesloadXMLDoc()put "books_comment.xmlLoad into xmlDoc and append text to the first comment element:
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].appendData(" Special Offer");
document.write(x[i].data);
document.write("
");
}
}
x=xmlDoc.getElementsByTagName("book")[0].childNodes;
for (i=0;i<x.length;i++)
{
if (x[i].nodeType==8)
{
//Process only comment nodes
x[i].appendData(" Special Offer");
document.write(x[i].data);
document.write("
");
}
}
Output:
125 Simple and Delicious Recipes (Hardcover) Special Offer
Try it Yourself »
In the example above, we use a loop and an if statement to perform processing only for comment nodes. The node type of comment nodes is 8.
Comment objectother extensions