createComment()
creates a new comment node, and returns it.
Syntax
CommentNode = document.createComment(data);
Parameters
- data
- A string containing the data to be added to the Comment.
Example
var docu = new DOMParser().parseFromString('<xml></xml>', 'application/xml'); var comment = docu.createComment('This is a not-so-secret comment in your document'); docu.getElementsByTagName('xml')[0].appendChild(comment); alert(new XMLSerializer().serializeToString(docu)); // Displays: <xml><!--This is a not-so-secret comment in your document--></xml>
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'document.createComment' in that specification. |
Living Standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
createComment | Chrome Full support 1 | Edge Full support 12 | Firefox Full support Yes | IE Full support Yes | Opera Full support Yes | Safari Full support 7 | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support Yes | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support