# ElementReplacer

class

Utility class allowing to hide existing HTML elements or replace them with given ones in a way that doesn't remove the original elements from the DOM.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/elementreplacer.ts#L14)

<a id="properties">

## Properties

<a id="member-_replacedElements">

### `_replacedElements: Array<object>` _(private)_

The elements replaced by [`replace`](#function-replace) and their replacements.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/elementreplacer.ts#L18)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor()`

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/elementreplacer.ts#L20)

<a id="function-replace">

### `replace( element, newElement? ) → void`

Hides the `element` and, if specified, inserts the the given element next to it.

The effect of this method can be reverted by [`restore`](#function-restore).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/elementreplacer.ts#L32)

#### Parameters

* `element: HTMLElement`

  The element to replace.

* `newElement?: HTMLElement`

  The replacement element. If not passed, then the `element` will just be hidden.

#### Returns

* `void`

<a id="function-restore">

### `restore() → void`

Restores what [`replace`](#function-replace) did.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/elementreplacer.ts#L45)

#### Returns

* `void`

---

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