DOM comment node (source code)

= DOM comment node
{c}

A <DOM comment node> stores comment character data in the <Document Object Model>. In <HTML> source, a normal comment can be written as `<!-- note -->`; parsing it produces a comment node rather than a <DOM element> or a <DOM text node> containing visible words.<DOM Standard by WHATWG>[§4.14, Comment interface and character data]{ref}<HTML Standard by WHATWG>[§13.1.7, Comments]{ref}

For example, `<p>A<!-- note -->B</p>` gives the paragraph three child <DOM nodes>: a text node containing A, a comment node, and a text node containing B. Its `childNodes.length` is three, while its element-only `children.length` is zero. Its `textContent` is `AB`: the comment does not contribute to this descendant-text result.<DOM Standard by WHATWG>[Node.textContent, descendant text content; ParentNode.children]{ref}

A traversal over every child can consequently encounter nodes absent from an element-only traversal. A <DOM comment node> can be inserted, moved or removed while editing the <DOM tree>, although it produces no ordinary displayed text. Removing the comment in this example leaves two adjacent text nodes; adjacency alone does not merge their object identities.

Comments are not a way to keep information secret from someone receiving a document: their data remains in the supplied source or document model. When generating comments, obey <HTML>'s syntax rather than assuming arbitrary text can always be placed between the delimiters.