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 

2x Salesforce MVP | Platform Champion | 18x Salesforce Certified | MuleSoft Certified | 8x Trailhead Ranger | TechForce Services | Sydney | Australia

Leave a Reply

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

*