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 »
Definition and Usage
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 |
Node | The created comment node. |
Browser Support
document.createComment()
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |