sorry for the title but I'm not sure what the correct terminology is for this issue. I am trying to dynamically generate a table of clickable elements using for loops in JavaScript. Each of the elements, when clicked, should trigger the same function but with different parameters. In my code I am setting the onClick
function up like so:
elementArray[i].onClick = function() { clickFunction(i) };
However, when I do this the clickFunction
is just taking whatever value i
is currently set to, not what it was when I set the onClick
function, which is what I want. Any ideas?