This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The Comment()
constructor returns a newly created Comment
object with the optional DOMString
given in parameter as its textual content.
Syntax
comment1 = new Comment(); // Create an empty comment
comment2
= new Comment("This is a comment");
Example
var comment = new Comment("Test");
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Comment: Comment' in that specification. |
Living Standard | Initial definition |
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 | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Comment() constructor | Chrome Full support Yes | Edge Full support ≤18 | Firefox Full support 24 | IE No support No | Opera Full support Yes | Safari ? | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 24 | Opera Android Full support Yes | Safari iOS ? | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
Note: For browsers where this constructor is not supported, Document.createComment()
may be suitable.