Element.setAttribute() (Method)

An accessor method to set a named custom attribute value.


DOM level - 1
JavaScript - 1.5
JScript - 3.0
Internet Explorer - 4.0
Netscape - 6.0
Opera - 5.0
Property/method value type:undefined
JavaScript syntax:-myElement.setAttribute(anAttribName, aValue)
-myElement.setAttribute(anAttribName, aValue, aCaseSense)
Argument list:aCaseSenseA flag indicating whether name lookup is case sensitive
anAttribNameAn attribute of an Element object
aValueA new value for the custom attribute

An attribute is added to the attributes collection for the object. Some attributes are presented as properties as well which is simply an alternative means of access to the same value. If that is the case then setting the attribute will also alter the property setting as well.

If the case sensitivity flag is set to true, then the name of the attribute must exactly match the name used in the HTML tag attribute, otherwise the results are uncertain.

See also:Element object, Element.getAttribute(), Element.mergeAttributes(), Element.removeAttribute()