up.event up.event.onClosest(element, eventType, [options], callback)
JavaScript function

This feature is experimental. Please share your experiences so we know what to keep or change.

Runs a callback when the given event is observed on the given element or its ancestors.

Example

up.event.onClosest(element, 'click', function() {
  // chip: Someone clicked on element or its ancestors
})

Parameters

element
required

The element to observe with its ancestors.

Type: Element
eventType
required

The event type to observe.

Type: string
[options.layer]
optional

Only observe ancestors in the given layer.

The layer is looked up with the observed element as { origin }. Pass 'origin' to observe ancestors in the element's own layer.

By default the callback runs for any ancestor in the DOM, including the element of a parent layer.

Type: string | up.Layer
callback
required

The callback to run.

It will be called with the observed event.

Type: Function(event)

Return value

A function that unsubscribes the callback.

When the element is destroyed, the callback will be unsubscribed automatically.

Type: Function