i'm using ajax to get some information to my page
the information received in an array so i use for loop to append them to my html page in this way :
for i to i less than my information i++
$('#ul').append("<li>"+info[i]+"</li>");
but i want to add a different .click event to every 'li' tag but i don't want to loop another time for this. is there any simple way to do this ?
I tried those solutions but nothing seems to work :
A)
for i to i less than my information i++
$('#ul').append( $("<li>"+info[i]+"</li>").click(function(){alert(i)}) );
return the last "i" value for all of them
B)
for i to i less than my information i++
$('#ul').append("<li>"+info[i]+"</li>").find('li:last-child').click( function( {alert(i)} ) );
return also the last "i" value for all of them
is there any simple way to do this ?