Javascript examples for DOM:Document createComment
The createComment() method creates a Comment node with the specified text.
Parameter | Type | Description |
---|---|---|
text | String | Optional. The text you want to be your comment, in the Comment object |
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:
<!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>