HTML DOM Document createComment()

Example

Create a comment node, and add it to the document:

const comment = document.createComment("My comments");
document.body.appendChild(comment);
Try it Yourself »

Description

The createComment() method creates a comment and returns the comment node.


Syntax

document.createComment(text)

Parameters

Parameter Description
text Optional.
The comment text.

Return Value

Type Description
NodeThe created comment node.

Browser Support

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

It is fully supported in all browsers:

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


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.