Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | DOM createComment() Method

  • Difficulty Level : Basic
  • Last Updated : 24 Jul, 2019

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
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!