Latest web development tutorials

XML DOM data attribute

Comment Object Reference Comment objects

Definition and Usage

data property sets or returns the comment text.

grammar

commentNode.data

Examples

The following code fragment uses loadXMLDoc () to " books_comment.xml " into xmlDoc, and outputs the comment text first <book> element:

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
document.write(x[i].data);
document.write("
");
}
}

The code above will output:

125 Simple and Delicious 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