---
schema_version: "1"
id: 1e178a22ef2b729fb004e67a406595201cd3c57497138bd574e52f08cd9c2595
title: Which Button Was Pressed?
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/js-cb/js-cb-which-button-pressed.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/js-cb-which-button-pressed.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 21946f56f18400e0ee9ab2b515bc15e6f34cffca5e27779ca34b376c2b435e10
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Which Button Was Pressed?

To find out which button was pressed in a component containing multiple buttons, use `Component.getLocalId()`.

Let’s look at an example with multiple `lightning:button` components. Each button has a unique local ID, set by an `aura:id` attribute.

```nolang
<!--c:buttonPressed-->
<aura:component>
    <aura:attribute name="whichButton" type="String" />
    
    <p>You clicked: {!v.whichButton}</p>

    <lightning:button aura:id="button1" label="Click me" onclick="{!c.nameThatButton}"/>
    <lightning:button aura:id="button2" label="Click me too" onclick="{!c.nameThatButton}"/>
</aura:component>
```

Use `event.getSource()` in the client-side controller to get the button component that was clicked. Call `getLocalId()` to get the `aura:id` of the clicked button.

```javascript
/* buttonPressedController.js */
({
    nameThatButton : function(cmp, event, helper) {
        var whichOne = event.getSource().getLocalId();
        console.log(whichOne);
        cmp.set("v.whichButton", whichOne);
    }
})
```

In the client-side controller, you can use one of the following methods to find out which button was clicked.

-   `event.getSource().getLocalId()` returns the `aura:id` of the clicked button.
-   `event.getSource().get("v.name")` returns the `name` of the clicked button.

**See Also**  


-   [Component IDs](https://developer.salesforce.com/docs/platform/aura-platform/components/components-ids.md)
-   [Finding Components by ID](https://developer.salesforce.com/docs/platform/aura-platform/guide/js-cb-find-by-id.md)

