Easy Tutorial
❮ Prop Document Firstchild Prop Text Length ❯

XML DOM createComment() Method


Definition and Usage

The createComment() method creates a comment node.

This method returns a Comment object.

Syntax

Parameter Description
data A string, this string specifies the data for the node.

Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and adds a comment node to the <book> element:

xmlDoc = loadXMLDoc("books.xml");

x = xmlDoc.getElementsByTagName('book');

for (i = 0; i < x.length; i++) {
  newComment = xmlDoc.createComment("Revised April 2008");
  x[i].appendChild(newComment);
}

for (i = 0; i < x.length; i++) {
  document.write(x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue);
  document.write(" - ");
  document.write(x[i].lastChild.nodeValue);
  document.write("<br>");
}

❮ Prop Document Firstchild Prop Text Length ❯