HTML DOM createComment()Method
Examples
Can create a comment node and insert it into an HTML document:
var c=document.createComment("My personal comments");
document.body.appendChild(c);
document.body.appendChild(c);
Output result:
<!--My personal comments-->
Try it Yourself »
Definition and Usage
The createComment() method creates a comment node.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the createComment() method
Syntax
document.createComment(text)
Parameters
| Parameters | Type | Description |
|---|---|---|
| text | String | Optional. The comment text to add. |
Return Value
| Type | Description |
|---|---|
| Comment object | The created comment node |
Technical Details
| DOM Version | Core Level 1 Document Object |
|---|
Other Extensions
Document Object