Value Binding with html elements in lightning Component

HTML Markup:

<a href="javascript:void(0)" onclick="{!c.onUserClick}" data-userid="{!AccountDetail.CreatedBy.Id}">
     {!AccountDetail.CreatedBy.Name}
</a>

Controller:
onUserClick : function(component,event,helper){
        var userId = event.currentTarget.getAttribute("data-userid");
        var navEvt = $A.get("e.force:navigateToSObject");
        navEvt.setParams({
            "recordId" : userId,
        });
        navEvt.fire()
}

Written by 

Salesforce MVP | Lightning Champion | 16x Salesforce Certified | Application Architect | 6x Trailhead Ranger | Techforce Services | Australia

Leave a Reply

Your email address will not be published. Required fields are marked *

*