COMMENT object (Object/DOM)

An object that represents a section of HTML enclosed in comment delimiter tags.

Availability:

DOM level - 1
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
Inherits from:CharacterData object
JavaScript syntax:IEmyCOMMENT = myDocument.all.anElementID
IEmyCOMMENT = myDocument.all.tags("COMMENT")[anIndex]
IEmyCOMMENT = myDocument.all[aName]
-myCOMMENT = myDocument.getElementById(anElementID)
-myCOMMENT = myDocument.getElementsByName(aName)[anIndex]
NmyCOMMENT = myDocument.createComment(aString)
-myCOMMENT = myDocument.getElementsByTagName("COMMENT")[anIndex]
HTML syntax:<!-- ... -->
Argument list:anIndexAn item within the collection
aStringA comment string
aNameThe name of an element
anElementIDThe ID attribute of an element
Object properties:text
Object methods:click(), getAttribute(), removeAttribute(), setAttribute()
Collections:all[], children[]

It is somewhat unlikely you would ever want to modify the contents of a comment tag. However, access to the text contained within it may be a way of passing hidden data values to your scripts without them being visible in the displayed page. Of course they would still be visible in the document source, but you might be able to avoid the creation of a <FORM> and hidden <INPUT> object.

Warnings:

See also:CharacterData object, Document.createComment(), Element object, Hiding scripts from old browsers

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
text n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
click()1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a1 1 n/a n/aWarning
getAttribute()1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a1 1 n/a n/aWarning
removeAttribute()1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a1 1 n/a n/aWarning
setAttribute()1.5 1.53.0 3.06.0 6.04.0 4.0 n/a n/a n/a1 1 n/a n/aWarning

Inheritance chain:

CharacterData object, Node object