I am dynamically generating a series of onclick events where an alert() is associated with loop number of the pretended content. My problem is that currently the alerts outputs the 'i' value of the last loop rather than the i'th loop associated with the pretended content. Any thoughts?
JavaScript:
for (i = 1; i < 4; i++) {
prepend_content = '<a href="#" id="img1_link_' + i + '" onclick="alert(i);">foo</a>';
$('#dynamic_div').prepend(prepend_content);
}
Many thanks.