Edit this page

up.event up.$on([element], events, [selector], [options], listener)
JavaScript function

This feature has been deprecated. Use up.on() with a callback that wraps the given native element in a jQuery collection.

Load unpoly-migrate.js 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.

If you're not using jQuery, use up.on() instead, which calls event handlers with a native element.

Example

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

Parameters

[element=document]
optional

The element on which to register the event listener.

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

events
required

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

string
[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.

string
[options.passive=false]
optional

Whether to register a passive event listener.

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

boolean
listener
required

The listener function that should be called.

The function takes the observed element as the first argument. The element's attached data is passed as a third argument.

Function(event, [element], [data])

Return value

A function that unbinds the event listeners when called.

Function()