Sets the value of the specified attribute.


 object.setAttribute(sAttrName, vValue [, iCaseSensitive])


sAttrName of type DOMString

A required string that specifies the name of the attribute.

vValue of type DOMString

The value to assign to the attribute.

iCaseSensitive of type Integer

An optional integer that specifies whether to use a case-sensitive search to locate the attribute. Can be one of the following values:


The case of sAttrName is respected.


Match sAttrName regardless of case.

Return Value

No return value.


  • If the specified attribute is not already present, the setAttribute method adds the attribute to the object and sets the value.

  • If your pages are displayed in IE7 mode, be careful when spelling attribute names. If you set iCaseSensitive to 1 and the sAttrName parameter does not have the same uppercase and lowercase letters as the attribute, a new attribute is created for the object. If two or more attributes have the same name, differing only in case, and iCaseSensitive is set to 0, this method assigns values only to the first attribute created with this name. All other attributes of the same name are ignored.