Newer Version Available

This content describes an older version of this product. View Latest

Finding Components by ID

Retrieve a component by its ID in JavaScript code. For example, you can add a local ID of button1 to the ui:button component.

1<ui: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.

You can also retrieve a component by its global ID, which is an ID generated during runtime.
1var cmp = $A.getComponent(globalId);
For example, the ui:button component renders as an HTML button element with this markup.
1<button class="default uiButton" data-aura-rendered-by="30:463;a">...</button>
Retrieve the component by using $A.getComponent("30:463;a").