Below is a simplified version of a code, which I am trying to make work for some hours now.
My aim is to get the id of the element, which a user clicks on, and pass the id value to a global variable targetId.
Unfortunately, although I manage to pass the id to a variable targetId, I can only access it within returnId function. If I try to access targetId outside of the function - it returns no value.
Why is that?
Thanks in advance for help! :)
var targetId;
function returnId(e) {
targetId = e.target.id;
}
element.addEventListener('click', returnId, false);