XML DOM createComment()Methods


Document object

Definition and Usage

The createComment() method creates a comment node.

This method returns a Comment object.

Syntax

createComment(data)

Parameter Description
data A string that specifies data for the node.


Example

The following code snippet usesloadXMLDoc()put "books.xml"Load into xmlDoc, and add a comment node to the <book> element:"

Example

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>"); }

Try it Yourself »

Document objectother extensions