Javascript Reference
Categories: Element

javascript Element getAttribute( )

@March 15, 2008, 1:22 a.m.
getAttribute( ) NN 6 IE 4 DOM 1  

getAttribute(attributeName) getAttribute(attributeName[,caseSensitivity])

  

Returns the value of the named attribute within the current element. If the attribute is reflected in the object model as a property, this method returns the same value as when reading the object's property. This is the preferred method for reading an element object attribute (i.e., property) value under the W3C DOM.

The attribute name you pass as a parameter is not case-sensitive in current browsers. IE, however, provides an optional second parameter that lets you force case-sensitivity in the attribute naming. This might encourage the reuse of the same attribute name but with different case lettersan ill-advised practice.

See the setAttribute( ) method for assigning values to attributes and creating new attribute/value pairs.

 
Parameters
 
  • The (case-insensitive by default) attribute name used in the HTML tag (not including the = symbol). While IE lets you switch between case-sensitivity settings, Netscape 6 does not demand case-sensitivity. But given the trend toward case-sensitive XHTML, it is best to get into the case-sensitive habit.
  • An optional integer value for IE only. Default value is 0 (not case-sensitive). If 1, the attribute in the HTML tag must match the case of the attributeName parameter exactly for its value to be returned.
 
Returned Value

The W3C DOM and Netscape 6 maintain attribute values exclusively as string data types. IE, however may return an attribute value as a string, number, or Boolean.

Under moderation.
ascendxiwij9 - 2016-04-16

Powered by Linode.