Comment: Comment() constructor
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.
The Comment() constructor returns a newly created
Comment object with the optional string given in
parameter as its textual content.
Syntax
js
new Comment()
new Comment(content)
Parameters
contentOptional-
A string representing the textual content of the comment.
Return value
A new Comment containing content, or the empty string if no parameter was given.
Example
js
const comment = new Comment("Test");
Specifications
| Specification |
|---|
| DOM # ref-for-dom-comment-comment① |
Browser compatibility
| desktop | mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Comment() constructor
|
|
|
|
|
|
|
|
|
|
|
|
|
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
See also
- The DOM interfaces index
Document.createComment()is an outdated alternative to this constructor.