---
name: "up.event"
area: "API"
kind: "module"
parent: "API reference"
url: "https://unpoly.com/api/up.event"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [API reference](https://unpoly.com/api.md)</nav>

# `up.event`

Features to emit and observe DOM events.

[`up.on()`](https://unpoly.com/api/up.on.md) listens on `document` or a given element, and can delegate to a selector so it also catches events from elements inserted later. It returns a function that unbinds the listener, and unbinds automatically when the element is destroyed. [`up.emit()`](https://unpoly.com/api/up.emit.md) emits a custom event with the given properties and returns it, so you can check whether a listener prevented it. An [`[up-emit]`](https://unpoly.com/api/up-emit.md) attribute emits a custom event when the element is clicked.

---

## Features {#features}

- ### [up.emit([target], eventType, [props])](https://unpoly.com/api/up.emit.md) (JavaScript function)

  Emits a custom event with the given name and properties.

- ### [[up-emit]](https://unpoly.com/api/up-emit.md) (HTML attribute)

  Emits a custom event when this element is clicked.

- ### [up.event.build([type], [props])](https://unpoly.com/api/up.event.build.md) (JavaScript function)

  Builds an event with the given type and properties.

- ### [up.event.halt(event)](https://unpoly.com/api/up.event.halt.md) (JavaScript function)

  Prevents the event from being processed further.

- ### [up.event.inputDevice](https://unpoly.com/api/up.event.inputDevice.md) (JavaScript property) (experimental)

  The class of input device used to cause the current event.

- ### [up.event.nobodyPrevents(eventType, eventProps)](https://unpoly.com/api/up.event.nobodyPrevents.md) (JavaScript function) (deprecated)

  Emits an event and returns whether no listener has prevented the default action.

- ### [up.event.onClosest(element, eventType, [options], callback)](https://unpoly.com/api/up.event.onClosest.md) (JavaScript function) (experimental)

  Runs a callback when the given event is observed on the given element _or its ancestors_.

- ### [up.event.onEscape(listener)](https://unpoly.com/api/up.event.onEscape.md) (JavaScript function) (experimental)

  Registers an event listener to be called when the user presses the `Escape` key.

- ### [up.off([element], types, listener)](https://unpoly.com/api/up.off.md) (JavaScript function)

  Unbinds an event listener previously bound with `up.on()`.

- ### [up.on([element], types, [selector], [options], listener)](https://unpoly.com/api/up.on.md) (JavaScript function)

  Listens to a DOM event on `document` or a given element.

- ### [up.$on([element], events, [selector], [options], listener)](https://unpoly.com/api/up.$on.md) (JavaScript function) (deprecated)

  Listens to an event on `document` or a given element. The event handler is called with the event target as a jQuery collection.

