HTML DOM Document createComment() Method

Definition and usage

createComment() Method to create a comment and return the comment node.

Example

Create a comment node and add it to the document:

const comment = document.createComment("My comments");
document.body.appendChild(comment);

Try it yourself

Syntax

document.createComment(data)

Parameter

Parameter description
data Optional. Comment text.

return value

type description
node A newly created comment node with text specified as data.

Browser support

document.createComment() It is a feature of DOM Level 1 (1998).

All browsers support it:

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support 9-11 Support Support Support Support