Set the type attribute of an input element:
Before setting the attribute:
After setting the attribute:
The setAttribute() method adds the specified attribute, and gives it the specified value.
If the specified attribute allready exists, only the value is set/changed
![]()
The setAttribute() method is supported in all major browsers.
Internet Explorer 8 and earlier does not support this method.
| Parameter | 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 |
No return value.
| DOM Version | Core Level 1 |
|---|
Your message has been sent to W3Schools.