Create a comment node, and insert it to the HTML document:
Click the button to create, and add, a comment to the HTML document.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from www . ja v a2 s . c o m var c = document.createComment("My personal comments"); document.body.appendChild(c); var x = document.getElementById("demo"); x.innerHTML = "A comment was added to this document, comments are invisible."; } </script> </body> </html>
The createComment()
method creates a Comment node with the specified text.
document.createComment(text);
Parameter Values
Parameter | Type | Description |
---|---|---|
text | String | Optional. The text you want to be your comment, in the Comment object |
The createComment()
method returns a Comment Object, representing the created Comment node.