Latest web development tutorials

XML DOM createComment () method

Document Object Reference Document Object

Definition and Usage

createComment () method creates a comment node.

This method returns a Comment object.

grammar

createComment(data)

参数 描述
data 字符串,这个字符串为节点规定数据。


Examples

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and to add comments to the node <book> element:

Examples

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName('book');
var newComment,newtext;
newtext="Revised April 2008";

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

try it"

Document Object Reference Document Object