Possible Duplicate:
Passing values to onclick
I have 100 elements with ids divNum0
,...,divNum99
. Each when clicked should call doTask
with the right parameter.
The code below unfortunately does not close i, and hence doTask
is called with 100 for all the elements.
function doTask(x) {alert(x);}
for (var i=0; i<100; ++i) {
document.getElementById('divNum'+i).addEventListener('click',function() {doTask(i);},false);
}
Is there someway I can make the function called with right parameters?