---
schema_version: "1"
id: 7761b017418cb16b23b8558203a21dacd5b4568196a305462f3447f70677d1f2
title: Working with Events in JavaScript
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/js/js-event.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/js-event.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 819b70081cabf0a462f801816048b555e4111e51bb75c22f7ed652934aa00412
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Working with Events in JavaScript

These are useful and common patterns for working with events in JavaScript.

Events communicate data across components. Events can contain attributes with values set before the event is fired and read when the event is handled.

## Fire an Event

Fire a component event or an application event that’s registered on a component.

```javascript
//Fire a component event
var compEvent = cmp.getEvent("sampleComponentEvent");
compEvent.fire();

//Fire an application event
var appEvent = $A.get("e.c:appEvent");
appEvent.fire();
```

For more information, see:

-   [Fire Component Events](https://developer.salesforce.com/docs/platform/aura-platform/events/events-component-fire.md)
-   [Fire Application Events](https://developer.salesforce.com/docs/platform/aura-platform/events/events-application-fire.md)

## Get an Event Name

To get the name of the event that’s fired:

```javascript
event.getSource().getName();
```

## Get an Event Parameter

To get an attribute that’s passed into an event:

```javascript
event.getParam("value");
```

## Get Parameters on an Event

To get all attributes that are passed into an event:

```javascript
event.getParams();
```

`event.getParams()` returns an object containing all event parameters.

## Get the Current Phase of an Event

To get the current phase of an event:

```javascript
event.getPhase();
```

If the event hasn’t been fired, `event.getPhase()` returns `undefined`. Possible return values for component and application events are `capture`, `bubble`, and `default`. Value events return `default`. For more information, see:

-   [Component Event Propagation](https://developer.salesforce.com/docs/platform/aura-platform/events/events-component-propagation.md)
-   [Application Event Propagation](https://developer.salesforce.com/docs/platform/aura-platform/events/events-application-propagation.md)

## Get the Source Component

To get the component that fired the event:

```javascript
event.getSource();
```

To retrieve an attribute on the component that fired the event:

```javascript
event.getSource().get("v.myName");
```

## Pause the Event

To pause the fired event:

```javascript
event.pause();
```

If paused, the event is not handled until `event.resume()` is called. You can pause an event in the `capture` or `bubble` phase only. For more information, see:

-   [Handling Bubbled or Captured Component Events](https://developer.salesforce.com/docs/platform/aura-platform/events/events-component-bubbling.md)
-   [Handling Bubbled or Captured Application Events](https://developer.salesforce.com/docs/platform/aura-platform/events/events-application-handling-phases.md)

## Prevent the Default Event Execution

To cancel the default action on the event:

```javascript
event.preventDefault();
```

For example, you can prevent a `lightning:button` component from submitting a form when it’s clicked.

## Resume a Paused Event

To resume event handling for a paused event:

```javascript
event.resume();
```

You can resume a paused event in the `capture` or `bubble` phase only. For more information, see:

-   [Handling Bubbled or Captured Component Events](https://developer.salesforce.com/docs/platform/aura-platform/events/events-component-bubbling.md)
-   [Handling Bubbled or Captured Application Events](https://developer.salesforce.com/docs/platform/aura-platform/events/events-application-handling-phases.md)

## Set a Value for an Event Parameter

To set a value for an event parameter:

```javascript
event.setParam("name", cmp.get("v.myName"));
```

If the event has already been fired, setting a parameter value has no effect on the event.

## Set Values for Event Parameters

To set values for parameters on an event:

```javascript
event.setParams({
    key : value
});
```

If the event has already been fired, setting the parameter values has no effect on the event.

## Stop Event Propagation

To prevent further propagation of an event:

```javascript
event.stopPropagation();
```

You can stop event propagation in the `capture` or `bubble` phase only.

