Can I use the aura:id
attribute to target an element for styling?
If so, is better to use aura:id
instead id
?
[SalesForce] Target an element with aura:id for CSS
Related Topic
- [SalesForce] get values in lightning:input with $A.createComponents
- [SalesForce] Lightning component.find(“aura:id”) returns an array consisting of one element
- [SalesForce] Two aura:id for one lightning component. Is it possible
- Apply CSS on lightning:button based on array of indexes
- Overlay Library – using referenceSelector to reference Element in Child Component
Best Answer
The
id
will let you get a reference to a specific DOM element.aura:id
will let you get a reference to a Component viacomponent.find("yourAuraId")
. Once you have a reference to the Aura component, you can call.getElement()
or.getElements()
to get the DOM that that component will render. It's probably better to go through the framework APIs and use aura:id, though both will do the job to let you manipulate the specific DOM elements.Note that you can also use the
$A.util.addClass()
API to add a CSS class on a Component. There's also has, remove, and toggleClass APIs.