How to use DOM Object CreateComment in JavaScript

In this article I am going to explain about DOM Object CreateComment() Method in JavaScript.
  • 1868

JavaScript Window object CreateComment() Method

JavaScript createComment() method use for create comment node with specified given text.

Syntax

document.createComment(text)

Example

<html>

<head>

    <script type="text/javascript">

        function myfun() {

            var mm = document.createComment("My personal comments");

            document.body.appendChild(mm);

            var pp = document.getElementById("txt");

            pp.innerHTML = "Hello friends how are you";

        };

    </script>

</head>

<body>

    <p id="txt">

        Click button for create comment</p>

    <button onclick="myfun()">

        click me</button>

</body>

</html>

 

Output


createcomment.gif

 

You may also want to read these related articles: here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.