Document createComment() Method - Javascript DOM

Javascript examples for DOM:Document createComment

Description

The createComment() method creates a Comment node with the specified text.

Parameter Values

Parameter Type Description
text String Optional. The text you want to be your comment, in the Comment object

Return Value:

A Comment Object, representing the created Comment node

The following code shows how to Create a comment node, and insert it to the HTML document:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from  w  w  w  .j  av  a 2  s  .  co m*/
    var c = document.createComment("comments");
    document.body.appendChild(c);
    var x = document.getElementById("demo");
    x.innerHTML = "A comment was added.";
}
</script>

</body>
</html>

Related Tutorials