I'm using infinite scroll made by Paul Irish which adds new content from paginator dynamically. I do get my other jquery's to work with .on method, but how to use it with .each? All I have come up with is it will fire multiple times or doesn't work at all on dynamically added items.
My code:
function delete() {
$('.delete').each(function(index, value) {
var id = $(this).data('id');
$(this).on("click", function() {
if (confirm('Are you sure you want to delete this?')) {
$(this).parents('.feed').fadeOut();
var suggests = $.ajax({
type: 'post',
datatype: 'html',
data: "id=" + id,
url: 'http://localhost/delete',
success: function(data) {}
});
}
});
});
};