Create a class attribute, with the value "democlass", and insert it to an H1 element:
Before creating the attribute:
After inserting the attribute:
The createAttribute() method creates an attribute with the specified name, and returns the attribute as an Attr object.
Read more about the Attr object in our Attr object reference.
![]()
The createAttribute() method is supported in all major browsers.
| Parameter | Type | Description |
|---|---|---|
| attributename | Attr object | Required. The name of the attribute you want to create |
| Type | Description |
|---|---|
| Node object | The created attribute |
| DOM Version | Core Level 1 |
|---|
Your message has been sent to W3Schools.