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:

1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<ui:button aura:id="button1" label="button1"/>
18

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:

1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<div id="{!globalId + '_footer'}"></div>

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

1swfobject.registerObject("clippy.codeblock-2", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17var globalId = cmp.getGlobalId();

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

1swfobject.registerObject("clippy.codeblock-3", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17var comp = $A.getCmp(globalId);

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