Activity › Forums › Salesforce® Discussions › What is the use of aura:id in Salesforce lightning component?
Tagged: Aura Id, Components, Javascript Code, Lightning Button, Local Id, Salesforce Lightning Component
-
What is the use of aura:id in Salesforce lightning component?
Posted by Laveena on November 4, 2019 at 1:49 PMWhat is the use of aura:id in salesforce lightning component?
Nikita replied 6 years, 6 months ago 3 Members · 2 Replies -
2 Replies
-
Hi,
aura:id is a local id. A local ID is an ID that is only scoped to the component. A local ID is often unique but it’s not required to be unique.
Ex.-<lightning:button aura:id=”button1″ label=”button1″/>
-
This reply was modified 6 years, 6 months ago by
Piyush.
-
This reply was modified 6 years, 6 months ago by
- [adinserter block='9']
-
Hi Laveena,
You can retrieve a component using its local ID in your JavaScript code. A local ID is an ID that is only scoped to the component. A local ID is often unique but it’s not required to be unique. Local ID is created by the aura:id attribute.
For Example:
<lightning: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.
find() returns different types depending on the result.
- If the local ID is unique, find() returns the component.
- If there are multiple components with the same local ID, find() returns an array of the components.
- If there is no matching local ID, find() returns undefined.
Log In to reply.