I've been working on adding a click event to a specific div that I created. While I was successful in doing so, the problem arises when I click on it and it displays undefined.
Below is the code snippet:
The variable 'resulta' is declared as a global array with objects
for(s = 0; s < resulta.length; s++) {
y = document.createElement('div');
y.setAttribute('class', 'eachssd');
var x = document.createTextNode(resulta[s].name);
y.appendChild(x);
o.appendChild(y);
y.addEventListener('click', function bnmhv() {location.href=resulta[s].datasrc}, false);
}
Thank you in advance for any help!