I have an a tag with an onclick event:

<a href="javascript:void(0);" onclick="{!c.handleClick}" data="{!a.Id}" 

And a JavaScript controller method to handle it:

handleClick: function (cmp, event, helper) {
    let el = event.target;

How do I get the value in the data attribute?

  • 1
    Is data supposed to be a custom html attribute? If so, shouldnt it be data-something?
    – glls
    May 9 '19 at 22:14

You need to use a data attribute, such as:

<a href="javascript:void(0);" onclick="{!c.handleClick}" data-record-id="{!a.Id}" 

Which you then access via dataset:

var recordId = event.currentTarget.dataset.recordId;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.