XML DOM createComment() method

Document object reference manual

Definition and usage

The createComment() method can create a comment node.

This method can return a Comment object.

Syntax:

createComment(data)
Parameter Description
data String value, which can specify data for this node.

Return value

Returns a newly created Comment node with the specified text.

Example

In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().

The following code snippet can add a comment node to the <book> element:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
var newComment,newtext;
newtext="Revised September 2006";
for (i=0;i<x.length;i++)
  {
  newComment=xmlDoc.createComment(newtext);;
  x[i].appendChild(newComment);
  }

Document object reference manual