Edit this page

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

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] ElementorjQuery optional

The element on which to register the event listener.

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

events string

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

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

[options.passive=false] boolean 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.

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

The listener function that should be called. The function takes the affected element as the first argument). If the element has an up-data attribute, its value is parsed as JSON and passed as a second argument.

Return value

Function()

A function that unbinds the event listeners when called.

This website uses cookies to improve usability and analyze traffic.
I accept or learn more