HTML DOM createComment()Method

Document 对象参考手册Document Object

Examples

Can create a comment node and insert it into an HTML document:

var c=document.createComment("My personal comments");
document.body.appendChild(c);

Output result:

<!--My personal comments-->

Try it Yourself »

Definition and Usage

The createComment() method creates a comment node.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the createComment() method


Syntax

document.createComment(text)

Parameters

Parameters Type Description
text String Optional. The comment text to add.

Return Value

Type Description
Comment object The created comment node

Technical Details

DOM Version Core Level 1 Document Object


Document 对象参考手册Document Object

Other Extensions