var count = 2; var loader = $('.infinite-loader'); $(window).scroll(function() { if($(window).scrollTop() == $(document).height() - $(window).height()) { if(count > total) { return false; } else { loadInfiniteContent(count); } count++; } }); function loadInfiniteContent(pageNumber) { loader.fadeIn(500); $.ajax({ url: '/wp-admin/admin-ajax.php', type: 'POST', data: 'action=infinite_scroll&page_no=' + pageNumber + '&loop_file=loop', success: function(html) { var element = $(html); //preprocess HTML before inserting into DOM element.find('.article-container, .article-container-grid').each(function() { // IF ID DOES EXIST, ADD CLASS TO ARTICLE CONTAINER if(cookieValue.indexOf($(this).data('id')) != -1) { $(this).addClass('readit'); if(!appended) { $('