Skip to content
Related Articles
Open in App
Not now

Related Articles

HTML | DOM createComment() Method

Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 13 Jul, 2022
Improve Article
Save Article

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. 


document.createComment( text )

Parameters: This method accepts single parameter text which is optional. This parameter is used to hold the comment string. 



<!DOCTYPE html>
        <title>DOM createComment() Method</title>
            h1, h2 {
            body {
        <h2>DOM createComment() Method</h2>
        <button onclick="geeks()">Submit</button>
        <p id="sudo"></p>
            function geeks() {
                var c = document.createComment("GFG comments");
                var x = document.getElementById("sudo");
                x.innerHTML = "Comments are Invisible!";



Supported Browsers: The browser supported by DOM createComment() Method property are listed below:

  • Google Chrome 1
  • Edge 12
  • Internet Explorer 6
  • Firefox 1
  • Opera 12.1
  • Safari 1

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!