I have an image list that has the ability to load more content via ajax. On default there are images loaded into the list. When the user scrolls another 4 items are added to the list. The list is refreshed via ajax every 15 seconds and just replaces the top 7 items in the list. The problem is when the 4 new items are added to the list the selector seems to ignore those items, so it doesn't select from a 0 index.
I know this sounds confusing so I'll try and demo with a simple example.
Ex
$(function () {
// Update ChannelStats
setTimeout(function () {
var refresh = setInterval(UpdateChannels, 15000);
UpdateChannels();
}, 15000);
function UpdateChannels() {
$.ajax({
type: "POST",
url: "ajax/ImageList.aspx/UpdateImages",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// Newest
var $newestResults = $('#newest .pcVideomaincontainer:lt(7)');
$newestResults.fadeOut('slow'), function () {
remove()
};
$.each($newestResults, function (index, value) {
$(this).delay(index * 250).animate({
opacity: 0
}, 250,
function () {
$(this).remove();
$('#pcContentHolder_newest').append(data.d.Newest.HtmlChannelSegments[index]);
});
});
});
}
});
[Note the order of the numbers - this is the order the images are loaded]
On initial page load the first images are loaded
1. On Initial Page Load for following images are loaded
1 2 3 4 5 6 7
2. When user scrolls the remaining for images are shown
1 2 3 4 5 6 7 8 9 10 11
3. Update script runs 1st time
8 9 10 11 1 2 3 4 5 6 7
4. Update script runs 2nd time
4 5 6 7 1 2 3 4 5 6 7
5. Each and every subsequent time the update script runs the order is
4 5 6 7 1 2 3 4 5 6 7
From what I can tell is that those 4 newly added elements are not included in the
$('#newest .pcVideomaincontainer:lt(7)')
selection. I'm not sure how I could use "live" in this scenario, or if there is some other technique.