createComment() method
HTML DOM createComment() Method
Instance
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p id="demo">单击按钮改HTML文档添加一个注释</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var c=document.createComment("My personal comments"); document.body.appendChild(c); var x=document.getElementById("demo"); x.innerHTML="这个文件现在包含一个注释,但如你所知,注释是看不见的。"; }; </script> </body> </html>
Run Example»
Click the "Run Example" button to view the online example
Definition and usage
The createComment() method can create a comment node.
Browser support
All major browsers support the createComment() method
Syntax
document.createComment(text)
Parameters
Parameters | Type | Description |
---|---|---|
text | String | Optional. Comment text to add. |
Return value
Type | Description |
---|---|
Comment object | Created comment node |
Technical details
DOM version | Core Level 1 Document Object |
---|