[SalesForce] Target an element with aura:id for CSS

Can I use the aura:id attribute to target an element for styling?
If so, is better to use aura:id instead id?

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 via component.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.