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.


comment1 = new Comment(); // Create an empty comment
comment2 = new Comment("This is a comment");


var comment = new Comment("Test");


Specification Status Comment
The definition of 'Comment: Comment' in that specification.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Comment() constructor
Chrome Full support YesEdge Full support ≤18Firefox Full support 24IE No support NoOpera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesFirefox Android Full support 24Opera Android Full support YesSafari iOS ? Samsung Internet Android Full support Yes


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