Finding Components by ID

Retrieve a component by its ID in JavaScript code.

Use aura:id to add a local ID of button1 to the lightning:button component.

<lightning:button aura:id="button1" label="button1"/>

You can find the component by calling cmp.find("button1"), where cmp is a reference to the component containing the button. The find() function has one parameter, which is the local ID of a component within the markup.

find() returns different types depending on the result.