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, 2019 at 22:14

1 Answer 1


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;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .