Latest web development tutorials

HTML DOM createComment () method

Document Object Reference Document Object

Examples

You can create a comment node, and into an HTML document:

var c=document.createComment("My personal comments");
document.body.appendChild(c);

Output:

<!--My personal comments-->

try it"

Definition and Usage

createComment () method to create a comment node.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support createComment () method


grammar

document.createComment(text)

parameter

参数 类型 描述
text String 可选. 添加的注释文本。

return value

类型 描述
Comment object 创建的注释节点

technical details

DOM version Core Level 1 Document Object


Document Object Reference Document Object