The createComment()
method creates a Comment node from the specified text.
createComment |
Yes | Yes | Yes | Yes | Yes |
document.createComment(text)
The optional text is a String type value representing text content in the Comment object.
A Comment object.
The following code shows how to create a comment node, and insert it to the HTML document.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--from w w w .j a v a2s. c o m-->
<script>
function myFunction()
{
var c = document.createComment("My personal comments");
document.body.appendChild(c);
var x = document.getElementById("demo");
x.innerHTML = "comments";
}
</script>
</body>
</html>
The code above is rendered as follows: