Search w3schools.com:

SHARE THIS PAGE

DOM Document createComment() Method

Document Object Reference Document Object

Example

Create a comment node, and insert it to the HTML document:

var c=document.createComment("My personal comments");
document.body.appendChild(c);

The result will be:

<!--My personal comments-->

Try it yourself »

Definition and Usage

The createComment() method creates a Comment node with the specified text.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The createComment() method is supported in all major browsers.


Syntax

document.createComment(text)

Parameters

Parameter Type Description
text String Optional. The text you want to be your comment, in the Comment object

Return Value

Type Description
Comment object The created Comment node

Technical Details

DOM Version Core Level 1


Document Object Reference Document Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]