Open In App
Related Articles

HTML DOM createComment() Method

Improve Article
Save Article
Like 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 that 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. 

Example: In this example, we will use createComment() method


<!DOCTYPE html>
    <title>DOM createComment() Method</title>
        h2 {
            color: green;
            font-weight: bold;
    <h2>DOM createComment() Method</h2>
    <button onclick="geeks()">
    <p id="sudo"></p>
        function geeks() {
            let c = document.createComment("GFG comments");
            let x = document.getElementById("sudo");
            x.innerHTML = "Comments are Invisible!";


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

  • Google Chrome 1
  • Edge 12
  • Firefox 1
  • Opera 12.1
  • Safari 1

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 03 Aug, 2023
Like Article
Save Article
Similar Reads
Related Tutorials