Newer Version Available

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

Component IDs

A component has two types of IDs: a local ID and a global ID.

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:

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.

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:

You can use the getGlobalId() function in JavaScript to get a component's global ID.

You can also do the reverse operation and get a component if you have its global ID.

For more information, see the JavaScript API at https://<mySalesforceInstance>.lightning.force.com/auradocs/reference.app, where <mySalesforceInstance> is the name of the instance hosting your org; for example, na1.

Note