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

Event

[target=document]
optional

The element on which the event is triggered.

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

eventType
required

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

string
[props={}]
optional

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

Options

[props.layer]
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.

up.Layerstringnumber
[props.target=document]
optional

The element on which the event is triggered.

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

[props.log]
optional

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

Pass false to not log this event emission.

stringArray

Return value

The emitted event object.