The comment type represents the content of comment within <!---  ---> symbols in a HTML document.

The comment type has following characteristics:

  • nodeType : 8
  • nodeName : #comment
  • nodeValue: content of the comment
  • parentNode : Document or Element
  • childNode : None.

The comment type has all string manipulation methods of the text type except splitText(). The comment node can be accessed as a childNode of the parent using nodeValue or data property.

The comment node can be created using createComment() method and with passing the comment string to the function. Comment nodes cannot be created and accessed after the </html> closing tag.

NOTE: These nodes are rarely used to create and access comments because of the no real need for it.

Example with creating a comment type node in DOM


›› go to examples ››