Edit this page

up.event up.emit([target], eventType, [props])
JavaScript function

Emits a custom event with the given name and properties.

The event will be dispatched on the document or on the given element.

You can listen to events of that type using addEventListener() or up.on().

Example

up.on('my:event', function(event) {
  console.log(event.foo)
})

up.emit('my:event', { foo: 'bar' })
// Prints "bar" to the console

Parameters

[target=document] ElementorjQuery optional

The element on which the event is triggered.

If omitted, the event will be emitted on the document.

eventType string

The event type, e.g. my:event.

[props={}] Object optional

A list of properties to become part of the event object that will be passed to listeners.

[props.layer] up.Layerorstringornumber optional

The layer on which to emit this event.

If this property is set, the event will be emitted on the layer's outmost element. Also up.layer.current will be set to the given layer while event listeners are running.

[props.log] stringorArray optional experimental

A message to print to the log when the event is emitted.

Pass false to not log this event emission.

[props.target=document] ElementorjQuery optional

The element on which the event is triggered.

Alternatively the target element may be passed as the first argument.

Return value

The emitted event object.