I have the following event listener - how can I get the value of the data attribute of the clicked link. The console give me undefined in the example below?
var removeLink = Dropzone.createElement("<a class='dz-remove' href='javascript:undefined;' data-file-id='2' >Remove file</a>");
removeLink.addEventListener("click", (e) => {
e.preventDefault();
e.stopPropagation();
var a = $(this);
console.log(a.attr("data-file-id"));
});
I can get it to work if I use the following syntax but I need to use the arrow function so that I can access some other properties:
removeLink.addEventListener("click", function (e) { ...});
I've tried the following but that get some other id altogether:
var a = $(e.currentTarget);
console.log(a.attr("data-file-id"));