2021-04-08 05:08:24 +08:00
|
|
|
|
# updateAttributes
|
|
|
|
|
The `updateAttributes` command sets attributes of a node or mark to new values. Not passed attributes won’t be touched.
|
|
|
|
|
|
2021-05-28 04:19:11 +08:00
|
|
|
|
See also: [extendMarkRange](/api/commands/extend-mark-range)
|
2021-04-08 05:08:24 +08:00
|
|
|
|
|
2021-05-28 04:19:11 +08:00
|
|
|
|
## Parameters
|
2021-04-08 05:08:24 +08:00
|
|
|
|
`typeOrName: string | NodeType | MarkType`
|
|
|
|
|
|
|
|
|
|
Pass the type you want to update, for example `'heading'`.
|
|
|
|
|
|
2021-04-21 15:43:31 +08:00
|
|
|
|
`attributes: Record<string, any>`
|
2021-04-08 05:08:24 +08:00
|
|
|
|
|
|
|
|
|
This expects an object with the attributes that need to be updated. It doesn’t need to have all attributes.
|
|
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
```js
|
|
|
|
|
// Update node attributes
|
2021-04-08 06:13:51 +08:00
|
|
|
|
editor.commands.updateAttributes('heading', { level: 1 })
|
2021-04-08 05:08:24 +08:00
|
|
|
|
|
|
|
|
|
// Update mark attributes
|
2021-04-08 06:13:51 +08:00
|
|
|
|
editor.commands.updateAttributes('highlight', { color: 'pink' })
|
2021-04-08 05:08:24 +08:00
|
|
|
|
```
|
|
|
|
|
|