createComment (W3C DOM Core method)

Spec
Version Depr. Static
DOM1 No No
Browser support (more…)
IE6+ FF1.5+ SA1.3+ OP9+
Full Full Full Full
Returns
Comment

Example

var comment = document.createComment('Why do I have to be Mr Pink?');

The example above creates a Comment node containing the data Why do I have to be Mr Pink?.

The end result of that operation is this comment:

<!--Why do I have to be Mr Pink?-->

Arguments

data (DOMString) required

The data for the comment.

Description

Create a Comment node with the specified data.

The created comment can then be added to the document using Node methods such as appendChild or insertBefore.

Return value

The created comment node.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.5 2.0 3.0 1.3 2.0 3.0 9.0 9.5
Partial Full Full Full Full Full Full Full Full Full Full

Internet Explorer 5.5 in HTML doesn't implement this method (it returns undefined).

User-contributed notes

There are no comments yet.

Related Products