HTML DOM setAttribute() method
Example
Set the attribute type of the input element:
document.getElementsByTagName("INPUT")[0].setAttribute("type","button");
Before setting the attribute:
After setting the attribute:
Try it »
Definition and Usage
The setAttribute() method creates or changes an attribute.
If the specified attribute already exists, only its value is set.
Browser support





All major browsers support the setAttribute() method
Internet Explorer 8 and earlier IE versions do not support this method.
Syntax
element
.setAttribute(
attributename
,
attributevalue
)
Parameters
| Parameters | Type | Description |
|---|---|---|
| attributename | String | Required. The name of the attribute you want to add. |
| attributevalue | String | Required. The value of the attribute you want to add. |
Return Value
No value is returned.
Technical Details
| DOM version | Core Level 1 Element Object |
|---|
Element object