Element.getAttribute() (Method)

An accessor for reading named custom attributes.


DOM level - 1
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
Opera - 5.0
Property/method value type:String primitive
JavaScript syntax:-myElement.getAttribute(anAttribName)
-myElement.getAttribute(anAttribName, aCaseSense)
Argument list:aCaseSenseA flag to indicate a case-sensitive lookup
anAttribNameAn attribute of an Element object

This is an accessor method which is used to access named attributes of an Element object. Attributes are not properties in the strict sense of the word, but may be accessible as if they were in some implementations.

This accessor is intended to provide a means of managing custom attributes.

It would be logical to assume that attributes are named uniquely but if several share the same name, differing only in case sensitivity, then if a case insensitive search is used you may not retrieve the one you expect. It is likely that you'll be given the last one that occurs, but this may be implementation-dependent.

The case sensitive flag should be set to the Boolean true value to force a case-sensitive search and false to ignore the case of letters in the attribute name.

The following values can be passed in the optional case sensitive flag argument:

The result will be value of the attribute. If the element does not have an attribute of the specified name, a null value is returned.


See also:Element object, Element.removeAttribute(), Element.setAttribute(), style.getAttribute()