JSFiddle - React, Tailwind, and code Playground
HTML
<div id="someId">div1</div> <br/>
<div id="someId2">div2</div>
JavaScript
var event = ['click', 'click'];
var element = ['#someId', '#someId2'];
for (i = 0; i < event.length; i++)
{
$(document).on(event[i], element[i], function ()
{
foo(i); // would like this to be the value of i when the function was created
});
}
function foo(arg)
{
alert(arg);
}