---
title: "EventEmitter"
---
# EventEmitter

Defined in: [src/core/event-emitter/event-emitter.ts:33](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L33)

The module editor's event manager

## Implements

- [`IEventEmitter`](../interfaces/types.IEventEmitter.html)

### Constructor

**new EventEmitter**(`doc?`): `EventEmitter`

Defined in: [src/core/event-emitter/event-emitter.ts:764](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L764)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `doc?` | [`Document`](https://developer.mozilla.org/docs/Web/API/Document) |

#### Returns

`EventEmitter`

### \_\_key

`readonly` **\_\_key**: `string` = `'__JoditEventEmitterNamespaces'`

Defined in: [src/core/event-emitter/event-emitter.ts:56](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L56)

***

### currents

**currents**: `string`[] = `[]`

Defined in: [src/core/event-emitter/event-emitter.ts:209](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L209)

#### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`currents`](../interfaces/types.IEventEmitter.html#currents)

#### Get Signature

**get** **current**(): `string`

Defined in: [src/core/event-emitter/event-emitter.ts:205](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L205)

Get current event name

##### Example

```javascript
parent.e.on('openDialog closeDialog', function () {
    if (parent.e.current === 'closeDialog') {
        alert('Dialog was closed');
    } else {
        alert('Dialog was opened');
    }
});
```

##### Returns

`string`

Get current event name

#### Example

```javascript
parent.e.on('openDialog closeDialog', function () {
    if (parent.e.current === 'closeDialog') {
        alert('Dialog was closed');
    } else {
        alert('Dialog was opened');
    }
});
```

#### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`current`](../interfaces/types.IEventEmitter.html#current)

### mute()

**mute**(`event?`): `this`

Defined in: [src/core/event-emitter/event-emitter.ts:38](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L38)

Doesn't start any handler

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `event?` | `string` |

#### Returns

`this`

#### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`mute`](../interfaces/types.IEventEmitter.html#mute)

***

### isMuted()

**isMuted**(`event?`): `boolean`

Defined in: [src/core/event-emitter/event-emitter.ts:43](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L43)

No handlers are triggered for the event

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `event?` | `string` |

#### Returns

`boolean`

#### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`isMuted`](../interfaces/types.IEventEmitter.html#ismuted)

***

### unmute()

**unmute**(`event?`): `this`

Defined in: [src/core/event-emitter/event-emitter.ts:51](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L51)

Returns event handling

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `event?` | `string` |

#### Returns

`this`

#### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`unmute`](../interfaces/types.IEventEmitter.html#unmute)

***

#### Call Signature

**on**(`events`, `callback`, `options?`): `this`

Defined in: [src/core/event-emitter/event-emitter.ts:229](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L229)

Sets the handler for the specified event ( Event List ) for a given element

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `events` | [`CanArray`](../modules/types.html#canarray)\<`string`\> |
| `callback` | [`CallbackFunction`](../interfaces/types.CallbackFunction.html) |
| `options?` | [`IEventEmitterOnOptions`](../interfaces/types.IEventEmitterOnOptions.html) |

##### Returns

`this`

##### Examples

```javascript
// set global handler
editor.events.on('beforeCommand', function (command) {
    alert('command');
});
```
*

```javascript
// set global handler
editor.events.on(document.body, 'click', function (e) {
    alert(this.href);
});
```

##### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`on`](../interfaces/types.IEventEmitter.html#on)

#### Call Signature

**on**(`subjects`, `events`, `callback`, `options?`): `this`

Defined in: [src/core/event-emitter/event-emitter.ts:235](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L235)

Sets the handler for the specified event ( Event List ) for a given element

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `subjects` | [`CanArray`](../modules/types.html#canarray)\<`object` \| [`Window`](https://developer.mozilla.org/docs/Web/API/Window) \| [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement)\> |
| `events` | [`CanArray`](../modules/types.html#canarray)\<`string`\> |
| `callback` | [`CallbackFunction`](../interfaces/types.CallbackFunction.html) |
| `options?` | [`IEventEmitterOnOptions`](../interfaces/types.IEventEmitterOnOptions.html) |

##### Returns

`this`

##### Examples

```javascript
// set global handler
editor.events.on('beforeCommand', function (command) {
    alert('command');
});
```
*

```javascript
// set global handler
editor.events.on(document.body, 'click', function (e) {
    alert(this.href);
});
```

##### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`on`](../interfaces/types.IEventEmitter.html#on)

***

### one()

**one**(`eventsOrSubjects`, `callbackOrEvents`, `optionsOrCallback`, `opts?`): `this`

Defined in: [src/core/event-emitter/event-emitter.ts:389](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L389)

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `eventsOrSubjects` | [`CanArray`](../modules/types.html#canarray)\<`string`\> \| [`CanArray`](../modules/types.html#canarray)\<`object` \| [`Window`](https://developer.mozilla.org/docs/Web/API/Window) \| [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement)\> |
| `callbackOrEvents` | [`CallbackFunction`](../interfaces/types.CallbackFunction.html)\<`any`\> \| [`CanArray`](../modules/types.html#canarray)\<`string`\> |
| `optionsOrCallback` | `void` \| [`CallbackFunction`](../interfaces/types.CallbackFunction.html)\<`any`\> \| [`IEventEmitterOnOptions`](../interfaces/types.IEventEmitterOnOptions.html) |
| `opts?` | [`IEventEmitterOnOptions`](../interfaces/types.IEventEmitterOnOptions.html) |

#### Returns

`this`

#### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`one`](../interfaces/types.IEventEmitter.html#one)

***

#### Call Signature

**off**(`events`, `callback?`): `this`

Defined in: [src/core/event-emitter/event-emitter.ts:454](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L454)

Disable all handlers specified event ( Event List ) for a given element. Either a specific event handler.

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `events` | [`CanArray`](../modules/types.html#canarray)\<`string`\> |
| `callback?` | [`CallbackFunction`](../interfaces/types.CallbackFunction.html)\<`any`\> |

##### Returns

`this`

##### Example

```javascript
var a = {name: "Anton"};
parent.e.on(a, 'open', function () {
    alert(this.name);
});

parent.e.fire(a, 'open');
parent.e.off(a, 'open');
var b = {name: "Ivan"}, hndlr = function () {
 alert(this.name);
};
parent.e.on(b, 'open close', hndlr);
parent.e.fire(a, 'open');
parent.e.off(a, 'open', hndlr);
parent.e.fire(a, 'close');
parent.e.on('someGlobalEvents', function () {
  console.log(this); // parent
});
parent.e.fire('someGlobalEvents');
parent.e.off('someGlobalEvents');
```

##### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`off`](../interfaces/types.IEventEmitter.html#off)

#### Call Signature

**off**(`subjects`, `events?`, `callback?`): `this`

Defined in: [src/core/event-emitter/event-emitter.ts:456](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L456)

Disable all handlers specified event ( Event List ) for a given element. Either a specific event handler.

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `subjects` | [`CanArray`](../modules/types.html#canarray)\<`object` \| [`Window`](https://developer.mozilla.org/docs/Web/API/Window) \| [`HTMLElement`](https://developer.mozilla.org/docs/Web/API/HTMLElement)\> |
| `events?` | [`CanArray`](../modules/types.html#canarray)\<`string`\> |
| `callback?` | [`CallbackFunction`](../interfaces/types.CallbackFunction.html)\<`any`\> |

##### Returns

`this`

##### Example

```javascript
var a = {name: "Anton"};
parent.e.on(a, 'open', function () {
    alert(this.name);
});

parent.e.fire(a, 'open');
parent.e.off(a, 'open');
var b = {name: "Ivan"}, hndlr = function () {
 alert(this.name);
};
parent.e.on(b, 'open close', hndlr);
parent.e.fire(a, 'open');
parent.e.off(a, 'open', hndlr);
parent.e.fire(a, 'close');
parent.e.on('someGlobalEvents', function () {
  console.log(this); // parent
});
parent.e.fire('someGlobalEvents');
parent.e.off('someGlobalEvents');
```

##### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`off`](../interfaces/types.IEventEmitter.html#off)

***

#### Call Signature

**stopPropagation**(`events`): `void`

Defined in: [src/core/event-emitter/event-emitter.ts:576](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L576)

Stop execute all another listeners for this event

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `events` | `string` |

##### Returns

`void`

##### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`stopPropagation`](../interfaces/types.IEventEmitter.html#stoppropagation)

#### Call Signature

**stopPropagation**(`subject`, `eventsList`): `void`

Defined in: [src/core/event-emitter/event-emitter.ts:577](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L577)

Stop execute all another listeners for this event

##### Parameters

| Parameter | Type |
| ------ | ------ |
| `subject` | `object` |
| `eventsList` | `string` |

##### Returns

`void`

##### Implementation of

`IEventEmitter.stopPropagation`

***

#### Call Signature

**fire**(`subjectOrEvents`, ...`args`): `any`

Defined in: [src/core/event-emitter/event-emitter.ts:657](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L657)

Emits an event to all handlers and calls them

##### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `subjectOrEvents` | `string` | The object which is caused by certain events |
| ...`args` | `any`[] | Options for the event handler |

##### Returns

`any`

`false` if one of the handlers return `false`

##### Example

```javascript
var dialog = new Jodit.modules.Dialog();
parent.e.on('afterClose', function () {
    dialog.destruct(); // will be removed from DOM
});
dialog.open('Hello world!!!');
```
 or you can trigger native browser listener
```javascript
 var events = new Jodit.modules.EventEmitter();
 events.on(document.body, 'click',function (event) {
     alert('click on ' + event.target.id );
 });
 events.fire(document.body.querySelector('div'), 'click');
```

##### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`fire`](../interfaces/types.IEventEmitter.html#fire)

#### Call Signature

**fire**(`subjectOrEvents`, `eventsList`, ...`args`): `any`

Defined in: [src/core/event-emitter/event-emitter.ts:658](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L658)

Emits an event to all handlers and calls them

##### Parameters

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `subjectOrEvents` | `object` | The object which is caused by certain events |
| `eventsList` | `string` \| [`Event`](https://developer.mozilla.org/docs/Web/API/Event) | List of events , separated by a space or comma |
| ...`args` | `any`[] | Options for the event handler |

##### Returns

`any`

`false` if one of the handlers return `false`

##### Example

```javascript
var dialog = new Jodit.modules.Dialog();
parent.e.on('afterClose', function () {
    dialog.destruct(); // will be removed from DOM
});
dialog.open('Hello world!!!');
```
 or you can trigger native browser listener
```javascript
 var events = new Jodit.modules.EventEmitter();
 events.on(document.body, 'click',function (event) {
     alert('click on ' + event.target.id );
 });
 events.fire(document.body.querySelector('div'), 'click');
```

##### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`fire`](../interfaces/types.IEventEmitter.html#fire)

***

### destruct()

**destruct**(): `void`

Defined in: [src/core/event-emitter/event-emitter.ts:772](https://github.com/xdan/jodit/blob/main/src/core/event-emitter/event-emitter.ts#L772)

#### Returns

`void`

#### Implementation of

[`IEventEmitter`](../interfaces/types.IEventEmitter.html).[`destruct`](../interfaces/types.IEventEmitter.html#destruct)
