---
title: Events
project: jComponent V19
version: 19.194
section: reference
language: de
license: MIT
url: https://totaljs.es/docs/de/jcomponent-v19/19-194/reference/events/
updated: 2026-11-18T13:58:24.464Z
---

# Events

> Die Events, die die Bibliothek auslöst.

Verarbeite diese Events mit [ON()](../globals/#on) und entferne die Handler mit [OFF()](../globals/#off). Deine eigenen Events verwenden dieselben Funktionen zusammen mit [EMIT()](../globals/#emit).

## API

### ON('init', function() {})

Type: `event`

Läuft einmal, wenn die ersten Komponenten bereit sind, direkt vor `ready`.

Eine Seite ohne Komponenten löst dieses Event nicht aus.

Example: Beispiel
```js
ON('init', function() {
	console.log('init'); // init
});
```

### ON('ready', function() {})

Type: `event`

Läuft einmal, wenn die ersten Komponenten bereit sind.

Ein später registrierter Handler läuft sofort. Eine Seite ohne Komponenten löst dieses Event nicht aus.

Example: Beispiel
```js
ON('ready', function() {
	console.log('ready'); // ready
});
```

### ON('component', function(component) {})

Type: `event`

Läuft, wenn eine Komponente bereit ist.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | Die Komponente. |

Example: Beispiel
```js
ON('component', function(com) {
	console.log(com.path); // data.box
});
```

### ON('@name', function(component) {})

Type: `event`

Läuft, wenn eine Komponente mit diesem Namen bereit ist.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | Die Komponente. |

Example: Beispiel
```js
ON('@box', function(com) {
	console.log(com.name); // box
});
```

### ON('#id', function(component) {})

Type: `event`

Läuft, wenn eine Komponente mit dieser Kennung bereit ist.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `component` | `Component` | yes |  | Die Komponente. |

Example: Beispiel
```js
ON('#mybox', function(com) {
	console.log(com.id); // mybox
});
```

### ON('component.compile', function(name, declaration) {})

Type: `event`

Läuft, wenn eine Komponente deklariert wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Der Name. |
| `declaration` | `Object` | yes |  | Die Deklaration. |

Example: Beispiel
```js
ON('component.compile', function(name) {
	console.log(name); // hello
});
COMPONENT('hello', NOOP);
```

### ON('component.destroy', function(name, component) {})

Type: `event`

Läuft, wenn eine Komponente entfernt wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Der Name. |
| `component` | `Component` | yes |  | Die Komponente. |

Example: Beispiel
```js
ON('component.destroy', function(name) {
	console.log(name); // box
});
ON('ready', function() {
	FIND('box').remove();
});
```

### ON('destroy', function(name, component) {})

Type: `event`

Läuft, wenn eine Komponente entfernt wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Der Name. |
| `component` | `Component` | yes |  | Die Komponente. |

Example: Beispiel
```js
ON('destroy', function(name) {
	console.log(name); // box
});
ON('ready', function() {
	FIND('box').remove();
});
```

### ON('lazy', function(name, loading) {})

Type: `event`

Läuft, wenn eine Lazy-Komponente zu laden beginnt und fertig geladen ist.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Der Name. |
| `loading` | `Boolean` | yes |  | `true` am Anfang, `false` am Ende. |

Example: Beispiel
```js
ON('lazy', function(name, loading) {
	console.log(name, loading); // box true
});
setTimeout(() => SETTER('box', 'hello', 'Peter'), 500);
```

### ON('binder', function(binder) {})

Type: `event`

Läuft, wenn eine Datenbindung bereit ist.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `binder` | `Object` | yes |  | Die Bindung. |

Example: Beispiel
```js
ON('binder', function(binder) {
	console.log(binder.path); // user.name
});
```

### ON('plugin', function(plugin) {})

Type: `event`

Wird ausgeführt, wenn ein Plugin erstellt wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `plugin` | `Plugin` | yes |  | Das Plugin. |

Example: Beispiel
```js
ON('plugin', function(plugin) {
	console.log(plugin.name); // users
});
PLUGIN('users', NOOP);
```

### ON('plugin.destroy', function(plugin) {})

Type: `event`

Läuft, wenn ein Plugin entfernt wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `plugin` | `Plugin` | yes |  | Das Plugin. |

Example: Beispiel
```js
ON('plugin.destroy', function(plugin) {
	console.log(plugin.name); // users
});
// Declaring a plugin again removes the previous one
setTimeout(() => PLUGIN('users', NOOP), 300);
setTimeout(() => PLUGIN('users', NOOP), 600);
```

### ON('cmd', function(name, a, b, c, d, e) {})

Type: `event`

Läuft, bevor ein Befehl an Komponenten gesendet wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Der Befehl. |
| `a` | `Object` | yes |  | Bis zu fünf Argumente. |

Example: Beispiel
```js
ON('cmd', function(name, value) {
	console.log(name, value); // refresh 1
});
CMD('refresh', 1);
```

### ON('exec', function(path, a, b, c, d) {})

Type: `event`

Läuft, bevor [EXEC()](../globals/#exec) eine Funktion oder eine Plugin-Methode aufruft.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Das Ziel. |
| `a` | `Object` | yes |  | Bis zu vier Argumente. |

Example: Beispiel
```js
ON('exec', function(path, value) {
	console.log(path, value); // app.run 1
});
window.app = { run: NOOP };
EXEC('app.run', 1);
```

### ON('setter', function(selector, method, a, b) {})

Type: `event`

Läuft, bevor [SETTER()](../globals/#setter) Komponenten aufruft.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `selector` | `String` | yes |  | Der Selektor. |
| `method` | `String` | yes |  | Die Methode. |
| `a` | `Object` | yes |  | Die ersten beiden Argumente, `a` und `b`. |

Example: Beispiel
```js
ON('setter', function(selector, method, value) {
	console.log(selector, method, value); // box hello 1
});
SETTER('box', 'hello', 1);
```

### ON('env', function(name, value) {})

Type: `event`

Läuft, wenn eine Umgebungsvariable geschrieben wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Der Name. |
| `value` | `Object` | yes |  | Der Wert. |

Example: Beispiel
```js
ON('env', function(name, value) {
	console.log(name, value); // api /v1/
});
ENV('api', '/v1/');
```

### ON('import', function(url, target) {})

Type: `event`

Läuft, nachdem Inhalte importiert wurden.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | Die URL. Bei HTML-Inhalten beginnt sie mit `$import`. |
| `target` | `jQuery` | yes |  | Das Zielelement oder das erstellte `script`- oder `link`-Element. |

Example: Beispiel
```js
ON('import', function(url, target) {
	console.log(target.length); // 1
});
IMPORT('/part.html');
```

### ON('request', function(options) {})

Type: `event`

Läuft, bevor eine Anfrage gesendet wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `options` | `Object` | yes |  | Die Anfrage: `url`, `method`, `headers`, `data`, `upload`, `scope` und mehr. |

Setze `options.cancel = true`, um die Anfrage zu stoppen. `options.respond(response, [headers])` beantwortet sie ohne Server, und `options.throw(response, [headers], code)` beantwortet sie mit einem Fehler.

Example: Beispiel
```js
ON('request', function(options) {
	console.log(options.method, options.url); // GET /api/
	options.respond({ ok: true });
});
AJAX('GET /api/', NOOP);
```

### ON('response', function(output) {})

Type: `event`

Läuft, nachdem eine Antwort eingetroffen ist, vor dem Callback der Anfrage.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | Das Ergebnis: `url`, `method`, `status`, `response`, `raw`, `headers`, `error`, `duration` und mehr. |

Setze `output.process = false`, um den Callback der Anfrage zu überspringen.

Example: Beispiel
```js
ON('response', function(output) {
	console.log(output.status, output.response.ok); // 200 true
});
AJAX('GET /api/', NOOP);
```

### ON('error', function(output) {})

Type: `event`

Läuft, wenn eine Anfrage fehlschlägt.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `output` | `Object` | yes |  | Das Ergebnis der Anfrage. |

Das Event wird nicht ausgelöst, wenn `DEF.ajaxerrors` den Wert `true` hat.

Example: Beispiel
```js
ON('error', function(output) {
	console.log(output.status); // 500
});
AJAX('GET /api/', NOOP);
```

### ON('ERROR', function(response) {})

Type: `event`

Läuft, wenn [ERROR()](../globals/#error) einen Fehler findet.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `response` | `Object` | yes |  | Der geprüfte Wert. |

Example: Beispiel
```js
ON('ERROR', function(response) {
	console.log(response[0].error); // Invalid
});
ERROR([{ error: 'Invalid' }]);
```

### ON('knockknock', function(counter) {})

Type: `event`

Wird jede Minute ausgeführt.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | Die Anzahl der Durchläufe. |

Example: Beispiel
```js
ON('knockknock', function(counter) {
	console.log(counter); // 1
});
```

### ON('service', function(counter) {})

Type: `event`

Läuft jede Minute, direkt vor `knockknock`.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `counter` | `Number` | yes |  | Die Anzahl der Durchläufe. |

Example: Beispiel
```js
ON('service', function(counter) {
	console.log(counter); // 1
});
```

### ON('resize2', function() {})

Type: `event`

Läuft, nachdem sich die Größe des Fensters geändert hat.

Das Event ist um 300 Millisekunden verzögert und läuft außerdem einmal beim Start der Seite.

Example: Beispiel
```js
ON('resize2', function() {
	console.log(typeof(WW)); // number
});
```

### ON('scroll', function(area) {})

Type: `event`

Läuft, wenn das Scrollen in einer [SCROLLBAR()](../globals/#scrollbar) beginnt.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | Das gescrollte Element. |

Example: Beispiel
```js
ON('scroll', function(area) {
	console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
```

### ON('scrollidle', function(area) {})

Type: `event`

Läuft, wenn das Scrollen in einer [SCROLLBAR()](../globals/#scrollbar) endet.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `area` | `jQuery` | yes |  | Das gescrollte Element. |

Example: Beispiel
```js
ON('scrollidle', function(area) {
	console.log(area.length); // 1
});
var scrollbar = SCROLLBAR($('#box'), { native: true });
scrollbar.area.trigger('scroll');
```

### ON('visible', function(visible) {})

Type: `event`

Läuft, wenn die Seite in den Hintergrund wechselt oder von dort zurückkehrt.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `visible` | `Boolean` | yes |  | `true`, wenn die Seite sichtbar ist. |

Example: Beispiel
```js
ON('visible', function(visible) {
	console.log(visible); // true
});
$(window).trigger('visibilitychange');
```

### ON('@flag name', function(path, value, type) {})

Type: `event`

Läuft, wenn ein Path oder eine Methode mit dem benutzerdefinierten Flag `@name` verwendet wird.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | yes |  | Der Path. |
| `value` | `Object` | yes |  | Der Wert. |
| `type` | `Number` | yes |  | Der Änderungstyp. |

Example: Beispiel
```js
ON('@flag saved', function(path, value) {
	console.log(path, value); // user.age 30
});
SET('user.age @saved', 30);
```
