|
|
|
|
|
by theoretical
5622 days ago
|
|
It won't alert quite what you want - when you click on each element in the list, it will alert "4". This is because the function assigned to the click event of each li is bound to the "i" variable used in the loop by a closure. Variable i is incremented to 4 before the loop ends, so that is what each will print. You could use make the function used in the click handler take a parameter, then use partial function application (or currying) to fix the value of the parameter. |
|