---
name: "up.emit"
area: "API"
kind: "JavaScript function"
parent: "up.event module"
url: "https://unpoly.com/api/up.emit"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.event module](https://unpoly.com/api/up.event.md)</nav>

# up.emit([target], eventType, [props])

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()`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener) or [`up.on()`](https://unpoly.com/api/up.on.md).

<nav aria-label="Contents">

#### Contents

- [Example](#example)
- [Parameters](#parameters)
- [Return value](#return-value)

</nav>

## Example {#example}

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

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

---

## Parameters {#parameters}

### Event {#parameters-event}

#### [target=document] {#target}

(optional)

The element on which the event is triggered.

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

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) | [jQuery](https://learn.jquery.com/using-jquery-core/jquery-object/)

#### eventType {#eventType}

(required)

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

Type: string

#### [props={}] {#props}

(optional)

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

Type: [Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects)

### Options {#parameters-options}

#### [props.layer] {#props.layer}

(optional)

The [layer](https://unpoly.com/api/up.layer.md) on which to emit this event.

If this property is set, the event will be emitted on the [layer's outmost element](https://unpoly.com/api/up.Layer.prototype.element.md). Also [up.layer.current](https://unpoly.com/api/up.layer.current.md) will be set to the given layer while event listeners are running.

Type: [up.Layer](https://unpoly.com/api/up.Layer.md) | string | number

#### [props.target=document] {#props.target}

(optional)

The element on which the event is triggered.

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

Type: [Element](https://developer.mozilla.org/en-US/docs/Web/API/Element) | [jQuery](https://learn.jquery.com/using-jquery-core/jquery-object/)

#### [props.log] (Experimental) {#props.log}

(optional)

A message to print to the [log](https://unpoly.com/api/up.log.md) when the event is emitted.

Pass `false` to not log this event emission.

Type: string | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)

---

## Return value {#return-value}

The emitted event object.

Type: [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event)

