You are here: Reference > JavaScript > client-side > HTML DOM > objects > nodes and tags > CommentNode

CommentNode object

Browser support:
Allows inserting remarks into the source code.
Remarks can be helpful when you need to edit the code at a later time.
CommentNode objects are not rendered by browsers.
CommentNode objects make it possible to insert comments into the document as nodes (appendChild, insertBefore).

Syntax:

Methods that return the object:
object.createComment (data)
Related objects:
The base interface, through which you can add new functionalities to the CommentNode object, is the Comment interface.
If you want to see the HTML objects by categories, please visit this page.
HTML page for this element: !--

Possible members:

Properties
Methods
Style properties
baseURI
10
Returns the base URL for the object.
behaviorUrns
9
Represents a collection of the Uniform Resource Names for all behaviors attached to an element.
canHaveChildren
9
Retrieves a Boolean value that indicates whether the element can contain child elements.
canHaveHTML
9
Retrieves a Boolean value that indicates whether the element can contain HTML formatted text.
currentStyle
9
Represents the computed style settings for an element.
data
Sets or returns the text content of a CommentNode, TextNode or comment element.
id
9
Sets or retrieves a unique identifier for the object.
innerHTML
9
Sets or retrieves the inner HTML content (the source code between the opening and closing tags) of an element.
isContentEditable
9
Returns a Boolean value that indicates whether the contents of the object are editable by the user.
isDisabled
9
Returns a Boolean value that indicates whether the object is disabled.
isMultiLine
9
Returns a Boolean value that indicates whether the contents of an element can be multiline or not.
isTextEdit
9
Returns a Boolean value that indicates whether the createTextRange method can be used for the element.
length
Returns the number of characters within a TextNode, CommentNode or comment object.
nextSibling
Returns a reference to the next child of the current element's parent.
nodeName
Returns the name of the current node.
nodeType
Returns an integer that indicates the type of the node.
nodeTypeString
Returns the type of the current node as a string.
nodeValue
Sets or returns the value of the current node.
offsetParent
9
Returns a reference to the closest ancestor element in the DOM hierarchy from which the position of the current element is calculated.
outerHTML
9
Sets or retrieves the outer HTML content (the source code including the opening and closing tags) of an element.
outerText
9
Sets or returns the text content of an element including the text content of its descendants.
ownerDocument
Returns the document object that contains the current node.
parentElement
9
Returns the parent element of the object in the DOM hierarchy.
parentNode
Returns the parent element of the current node in the DOM hierarchy.
parentTextEdit
9
Returns the closest ancestor element of the current element in the DOM hierarchy that can be used to create a TextRange object.
previousSibling
Returns a reference to the previous node of the current element's parent.
readyState
9
Returns a string value that represents the state of the object.
runtimeStyle
9
Represents the overridden style settings for an element.
scopeName
9
Retrieves the local name of the namespace declared for the current element.
sourceIndex
9
Returns the position of the current object in the all collection of the document.
style
9
Represents the inline style settings for an element or a CSS rule.
tagName
9
Returns the tag name of the current element.
tagUrn
9
Sets or retrieves the Uniform Resource Name (URN) of the namespace declared for the current element.
text
Sets or returns a string that corresponds the contents of the element.
textContent
9
Sets or returns the text content of an element including the text content of its descendants.
uniqueID
9
Returns the unique identifier generated by the browser for the object.

Example HTML code 1:

This example illustrates the use of the comment tag:
<!-- This is a comment, the browser does not render it. -->
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the CommentNode object:
<head>
    <script type="text/javascript">
        function CreateComment () {
            var commentContainer = document.getElementById ("commentContainer");
            var comment = document.createComment ("Dynamically generated comment");
            commentContainer.appendChild (comment);
            alert (commentContainer.innerHTML);
        }
    </script>
</head>
<body>
    <div id="commentContainer"></div>
    <button onclick="CreateComment ();">Create a comment!</button>
</body>
Did you find this example helpful? yes no

Related pages:

External links:

User Contributed Comments

Post Content

Post Content