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 »
document.body.appendChild(comment);
Description
The createComment()
method creates a comment and returns the comment node.
Syntax
document.createComment(text)
Parameters
Parameter
Description
text
Optional.
The comment text.
The comment text.
Return Value
Type
Description
Node The 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 |