Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

HTML | DOM comment() constructor

  • Last Updated : 03 Oct, 2019

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


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

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.

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


  • 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
Recommended Articles
Page :

Start Your Coding Journey Now!