I'm creating a bunch of Divs based on the number items in an array that I recieve from an AJAX. All of the divs have a unique Id and I want to add a Click event to each of the generated Divs. I want the user to click on one of the generated divs which will then post some data. This is the code I use but it doesn't work.
c=data.length
for(i=0;i<c;i++){
$('#result').prepend('<div class="validation" id="lv_'+i+'">'+data[i]+'</div> ');
$("#lv_"+i).live('click', function(data){
.$post("setLocation", {lv: lv}, function(data){
alert(data);
});
});
}
live()has been deprecated to useon(). While this doesn't address your specific question, it's worth investigating. api.jquery.com/on