# RootAttributeOperation

class

Operation to change root element's attribute. Using this class you can add, remove or change value of the attribute.

This operation is needed, because root elements can't be changed through [`AttributeOperation`](module_engine_model_operation_attributeoperation-AttributeOperation.md). It is because [`AttributeOperation`](module_engine_model_operation_attributeoperation-AttributeOperation.md) requires a range to change and root element can't be a part of range because every [`ModelPosition`](module_engine_model_position-ModelPosition.md) has to be inside a root. [`ModelPosition`](module_engine_model_position-ModelPosition.md) can't be created before a root element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L29)

<a id="properties">

## Properties

<a id="member-affectedSelectable">

### `affectedSelectable: ModelSelectable` _(readonly)_

A selectable that will be affected by the operation after it is executed.

The exact returned parameter differs between operation types.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L96)

<a id="member-baseVersion">

### `baseVersion: number | null` _(inherited)_

[`version`](module_engine_model_document-ModelDocument.md#member-version) on which operation can be applied. If you try to [apply](module_engine_model_model-Model.md#function-applyOperation) operation with different base version than the [document version](module_engine_model_document-ModelDocument.md#member-version) the [model-document-applyOperation-wrong-version](module_utils_ckeditorerror-CKEditorError.md) error is thrown.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/operation.ts#L26)

<a id="member-batch">

### `batch: Batch | null` _(inherited)_

[Batch](module_engine_model_batch-Batch.md) to which the operation is added or `null` if the operation is not added to any batch yet.

Note, that a [non-document operation](#member-isDocumentOperation) has this property always set to `null`, and is never added to any batch.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/operation.ts#L40)

<a id="member-isDocumentOperation">

### `isDocumentOperation: boolean` _(readonly)_

Defines whether operation is executed on attached or detached [items](module_engine_model_item-ModelItem.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/operation.ts#L31)

<a id="member-key">

### `key: string` _(readonly)_

Key of an attribute to change or remove.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L38)

<a id="member-newValue">

### `newValue: unknown` _(readonly)_

New value of the attribute with given key or `null`, if operation should remove attribute.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L52)

<a id="member-oldValue">

### `oldValue: unknown` _(readonly)_

Old value of the attribute with given key or `null`, if attribute was not set before.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L45)

<a id="member-root">

### `root: ModelRootElement` _(readonly)_

Root element to change.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L33)

<a id="member-type">

### `type: 'addRootAttribute' | 'removeRootAttribute' | 'changeRootAttribute'` _(readonly)_

Operation type.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L83)

#### Static properties

<a id="static-member-className">

### `className: string` _(readonly)_

Name of the operation class used for serialization.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L193)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( root, key, oldValue, newValue, baseVersion )`

Creates an operation that changes, removes or adds attributes on root element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L65)

#### Parameters

* `root: ModelRootElement`

  Root element to change.

* `key: string`

  Key of an attribute to change or remove.

* `oldValue: unknown`

  Old value of the attribute with given key or `null`, if attribute was not set before.

* `newValue: unknown`

  New value of the attribute with given key or `null`, if operation should remove attribute.

* `baseVersion: number | null`

  Document [`version`](module_engine_model_document-ModelDocument.md#member-version) on which operation can be applied or `null` if the operation operates on detached (non-document) tree.

#### Related:

* [AttributeOperation](module_engine_model_operation_attributeoperation-AttributeOperation.md)

<a id="function-clone">

### `clone() → RootAttributeOperation`

Creates and returns an operation that has the same parameters as this operation.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L105)

#### Returns

* `RootAttributeOperation`

  Clone of this operation.

<a id="function-getReversed">

### `getReversed() → Operation`

See [`Operation#getReversed()`](module_engine_model_operation_operation-Operation.md#function-getReversed).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L112)

#### Returns

* `Operation`

<a id="function-toJSON">

### `toJSON() → unknown`

Custom toJSON method to solve child-parent circular dependencies.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L182)

#### Returns

* `unknown`

  Clone of this object with the operation property replaced with string.

<a id="function-_execute">

### `_execute() → void` _(internal)_

Executes the operation - modifications described by the operation properties will be applied to the model tree.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L171)

#### Returns

* `void`

<a id="function-_validate">

### `_validate() → void` _(internal)_

Checks whether the operation's parameters are correct and the operation can be correctly executed. Throws an error if operation is not valid.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L120)

#### Returns

* `void`

#### Static methods

<a id="static-function-fromJSON">

### `fromJSON( json, document ) → RootAttributeOperation` _(static)_

Creates `RootAttributeOperation` object from deserialized object, i.e. from parsed JSON string.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/model/operation/rootattributeoperation.ts#L203)

#### Parameters

* `json: any`

  Deserialized JSON object.

* `document: ModelDocument`

  Document on which this operation will be applied.

#### Returns

* `RootAttributeOperation`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
