The createComment() method is used to create a comment node with some specified text. This property is used to set a text value as a parameter which is of string type.
Syntax:
document.createComment( text )
Parameters: This method accepts single parameter text which is optional. This parameter is used to hold the comment string.
Example:
<!DOCTYPE html> <html> <head> <title>DOM createComment() Method</title> <style> h1, h2 { color:green; font-weight:bold; } body { text-align:center; } </style> </head> <body> <h1>GeeksForGeeks</h1> <h2>DOM createComment() Method</h2> <button onclick="geeks()">Submit</button> <p id="sudo"></p> <script> function geeks() { var c = document.createComment("GFG comments"); document.body.appendChild(c); var x = document.getElementById("sudo"); x.innerHTML = "Comments are Invisible!"; } </script> </body> </html> |
Output:

Supported Browsers: The browser supported by DOM createComment() Method property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- PHP | DOMDocument createComment() Function
- HTML | DOM HTML Object
- HTML | DOM isEqualNode() Method
- HTML | DOM History go() Method
- HTML | DOM Input Date stepUp() Method
- HTML | DOM console.warn() Method
- HTML | DOM console.clear() Method
- HTML | DOM blur() Method
- HTML | DOM createElement() Method
- HTML DOM queueMicrotask() Method
- HTML | DOM Location replace() Method
- HTML | DOM close() Method
- HTML | DOM createAttribute() Method
- HTML | DOM writeln() Method
- HTML | DOM console.trace() Method
- HTML | DOM console.table() Method
- HTML | DOM console.time() Method
- HTML | DOM createTextNode() Method
- HTML | DOM console.error() Method
- HTML | DOM console.count() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


