[SalesForce] Get title attribute from
  • element in Lightning Component
  • I have three "li" elements with unique title. I added aura:id="tabId" to "li" as well. In Lightning controller I'm getting all items using find function:

    var tabs = component.find('tabId');
    

    How can I get title attribute in controller for each "li"?

    Best Answer

    As sfdcfox figured out here attributes of HTML elements are accessible at component.get("v.HTMLAttributes"). This makes it possible to access the values in init methods, where getElement() would not work by design as described here.

    So in your case, this would work

    for (var li of component.find("tabId")) {
        var title = li.get("v.HTMLAttributes").title;
    }