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

# up.$on([element], events, [selector], [options], listener)

**This feature has been deprecated**. Use [`up.on()`](https://unpoly.com/api/up.on.md) with a callback that wraps the given native element in a jQuery collection.

Load [`unpoly-migrate.js`](https://unpoly.com/changes/upgrading.md) to polyfill deprecated features.

Listens to an event on `document` or a given element. The event handler is called with the event target as a [jQuery collection](https://learn.jquery.com/using-jquery-core/jquery-object/).

If you're not using jQuery, use [`up.on()`](https://unpoly.com/api/up.on.md) instead, which calls event handlers with a native element.

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

```
up.$on('click', 'a', function(event, $link) {
  console.log("Click on a link with destination %s", $link.attr('href'))
})
```

---

## Parameters {#parameters}

### [element=document] {#element}

(optional)

The element on which to register the event listener.

If no element is given, the listener is registered on the `document`.

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) | [jQuery](https://learn.jquery.com/using-jquery-core/jquery-object/)

### events {#events}

(required)

A space-separated list of types names to bind to.

Type: string

### [selector] {#selector}

(optional)

The selector of an element on which the event must be triggered. Omit the selector to listen to all events with that name, regardless of the event target.

Type: string

### [options.passive=false] {#options.passive}

(optional)

Whether to register a [passive event listener](https://developers.google.com/web/updates/2016/06/passive-event-listeners).

A passive event listener may not call `event.preventDefault()`. This in particular may improve the frame rate when registering `touchstart` and `touchmove` events.

Type: boolean

### listener {#listener}

(required)

The listener function that should be called.

The function takes the event as the first argument and the observed element as the second argument. The element's [attached data](https://unpoly.com/learn/data.md) is passed as a third argument.

Type: Function(event, [element], [[data](https://unpoly.com/learn/data.md)])

---

## Return value {#return-value}

A function that unbinds the event listeners when called.

Type: Function()

