Newer Version Available
Event Handling in Base Lightning Components
Because of their markup, you might expect to access DOM elements via event.target or event.currentTarget. However, this type of access breaks encapsulation because it provides access to another component’s DOM elements, which are subject to change.
LockerService, which will be enabled for all orgs in Summer ’17, enforces encapsulation. Use the methods described here to make your code compliant with LockerService.
To retrieve the component that fired the event, use event.getSource().
Reusing Event Handlers
event.getSource() helps you determine which component fired an event. Let’s say you have several buttons that reuse the same onclick handler. To retrieve the name of the button that fired the event, use event.getSource().get("v.name").
Retrieving the Active Component Using the onactive Handler
Components, such as lightning:tab and lightning:menuItem, support the onactive handler so that you can obtain a reference to the target component when it becomes active. Clicking the component multiple times invokes the handler once only.
Retrieving the ID and Value Using the onselect Handler
- lightning:buttonMenu
- lightning:tabset
- event.getParam("id")
- event.getParam("value")