Web/API/Comment/Comment

From Get docs

This is an experimental technologyCheck 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
DOMThe definition of 'Comment: Comment' in that specification. Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

Comment() constructor

Experimental'

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.


See also