I am trying to assign an onclick function to different types of items. So, within a for loop I have if(invType[i] != "empty")
within that if statement I have
if(invType[i] == "usable"){
document.getElementById(i).onclick = function(i){ return function(){useItem(invName[i],i)}; }(i);
}
if(invType[i] == "equipment"){
document.getElementById(i).onclick = function(i){ return function(){equipItem(invName[i],i)}; }(i);
}
only the last non-"empty"
item is getting assigned the onclick function, and I have no clue why. I need it to assign the onclick to every "usable"
or "equipment"
not just the last one.