Apologies for the vague title, but I am uncertain of the correct term for my issue. I am working on dynamically generating a table of clickable elements using for loops in JavaScript. Each element, when clicked, should execute the same function but with different parameters. In my current code, I am defining the onClick function as follows:
elementArray[i].onClick = function() { clickFunction(i) };
However, it seems that the clickFunction is only capturing the current value of i, rather than the value it had when the onClick function was set up. Any suggestions on how to resolve this?