XML DOM » Document » createComment

Syntax:
document.createComment(data)
data
The string data that will be assigned as the value of the new Comment object.

This method creates a Comment object whose value is the data supplied as the argument.

The createComment method creates a Comment object whose value is the text supplied as the argument. Creating an instance of this object does not automatically include it in the XML Document tree, and so its parentNode property is set to null.

Examples

Code:
var xml_doc = new
ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("quotations.xml");

var root = xml_doc.documentElement;
var comment = xml_doc.createComment("last updated January 1999");
root.appendChild (comment);

var curr_node = root.lastChild;
document.write (curr_node.nodeType);
document.write ("<br>" + curr_node.nodeName);
document.write ("<br>" + curr_node.nodeValue);
Output:
8
#comment
last updated January 1999
Explanation:

This example creates a Comment consisting of a last-updated statement, and appends it to the children of the document's root element. It then displays the new node's type, name and value.

Language(s): JavaScript

See Also: