Newer Version Available
Event Handling in Base Lightning Components
Because of their markup, you might expect to access DOM elements for base components 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.
Lightning Locker enforces encapsulation. Use the methods described here to make your code compliant with Lightning Locker.
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
When working with tabs, you want to know which one is active. The lightning:tab component enables you to obtain a reference to the target component when it becomes active using the onactive handler . 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")