Comment()

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

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Comment() constructor
Experimental
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

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