HTML | DOM comment() constructor

The comment() constructor in HTML DOM is used to return the newly created comment object with an optional parameter as string.

Syntax:

comment1 = new Comment(); // Create empty comment
comment2 = new Comment(String);

Parameters: This constructor accept single parameter string which holds the comment text.



Example: This example creating a comment object with “This is a comment” as a parameter.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML | DOM comment() constructor
    </title>
      
    <style>
        a:focus {
            background-color: magenta;
        }
    </style>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;"
        GeeksforGeeks 
    </h1>
  
    <h2>HTML comment object</h2>
      
    <button onclick="getcomment ();">
        Get comment
    </button>
      
    <p id='comment'></p>
  
    <script type="text/javascript">
        function getcomment() {
            let comment = 
                new Comment("This is a comment");
  
            console.log(comment);
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before Click the Button:
  • Click the button and see results on the console:

Supported Browsers: The browsers supported by HTML DOM comment() constructor are listed below:

  • Google Chrome
  • Firefox 24
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

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.



Improved By : shubham_singh



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.