2021-10-17 18:26:00 +02:00
|
|
|
---
|
2022-09-29 19:01:10 +02:00
|
|
|
title: Attributes.set()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 19:01:10 +02:00
|
|
|
The `Attributes.set()` method sets the attribute identified by `key` to value
|
|
|
|
`value`.
|
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
Attributes attributes.set(string key, string value)
|
|
|
|
```
|
|
|
|
|
2022-09-29 19:01:10 +02:00
|
|
|
## Example
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 19:01:10 +02:00
|
|
|
```js
|
|
|
|
const attr = new Attributes()
|
|
|
|
.add('class', 'classA')
|
|
|
|
.add('class', 'classB')
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 19:01:10 +02:00
|
|
|
const class = attr.get('class')
|
|
|
|
// class now holds: "classA classB"
|
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 19:01:10 +02:00
|
|
|
## Notes
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 19:01:10 +02:00
|
|
|
This will overwrite any value that's currently set on the attribute identified
|
|
|
|
by `key`.
|
2021-08-25 16:09:31 +02:00
|
|
|
|