Newer Version Available
Component IDs
Local IDs
A local ID is unique within a component and is only scoped to the component.
Create a local ID by using the aura:id attribute. For example:
1<ui:button aura:id="button1" label="button1"/>Find the button component by calling cmp.find("button1") in your client-side controller, where cmp is a reference to the component containing the button.
aura:id doesn't support expressions. You can only assign literal string values to aura:id.
To find the local ID for a component in JavaScript, use cmp.getLocalId().
Global IDs
Every component has a unique globalId, which is the generated runtime-unique ID of the component instance. A global ID is not guaranteed to be the same beyond the lifetime of a component, so it should never be relied on.
To create a unique ID for an HTML element, you can use the globalId as a prefix or suffix for your element. For example:
1<div id="{!globalId + '_footer'}"></div>You can use the getGlobalId() function in JavaScript to get a component's global ID.
1var globalId = cmp.getGlobalId();You can also do the reverse operation and get a component if you have its global ID.
1var cmp = $A.getComponent(globalId);