Following part of my javscript(using jquery).
list = ['a', 'b', 'c'];
for(var i = 0 ; i< list.length ; i++) {
$("<a>click here</a>").
click(function(){
foo(list[i]);
}).
appendTo('#sometag');
}
function foo(val) {
console.log(val);
}
always prints c, no matter which tag you click on. How do I print proper value ???
It seems that it is using the last value of i=3 and thus evaluating o c always