function isNumber(value) { return !isNaN(parseFloat(value)) && isFinite(value); } $('.carica-altro-blogs').click(function () { var row = Number($('#row').val()); var allcount = Number($('#all').val()); var rowperpage = Number($('#quante').val()); row = row + rowperpage; if (row <= allcount) { $("#row").val(row); $.ajax({ url: 'https://www.studiodanzainsieme.it/assets/ajax/getBlogs.php', type: 'post', data: {row: row, rowperpage: rowperpage}, beforeSend: function () { $('.carica-altro-blogs').text("Caricamento"); }, success: function (response) { // Setting little delay while displaying new content setTimeout(function () { var dati = JSON.parse(response); var html = ''; $.each(dati.contenuto, function (key, value) { let newDate = new Date(value.data_inizio_pubblicazione); newDate = newDate.toLocaleDateString(); console.log(key + ": " + JSON.stringify(value)); html += '
  • '; html += '
    '; html += '
    '; html += ''; html += ''; html += '
    '; html += '' + newDate + ''; html += ' '+stripTags(value.titolo_it)+' '; html += stripTags(value.testo_breve_it) + '
  • '; }); console.log(dati.tot); $newItem = $(html); $grid = $('.blog-wrapper'); $grid.isotope() .append($newItem) .isotope('appended', $newItem) if ($(window).width() > 768) { e = 0; $(".js-eq-altezza-descr-blogs").each(function () { $(this).height() > e && (e = $(this).height()) } ), $(".js-eq-altezza-descr-blogs").height(e) } // layout Isotope after each image loads //$grid.imagesLoaded().progress(function () { // $grid.isotope('layout'); //}); var rowno = row + rowperpage; // checking row value is greater than allcount or not if (rowno > allcount) { // Change the text and background $('.carica-altro-blogs').hide(); //$('.load-more').css("background","darkorchid"); } else { $('.carica-altro-blogs').text("Carica altro"); } }, 100); } }); } else { $('.carica-altro-blogs').text("Caricamento"); // Setting little delay while removing contents setTimeout(function () { // When row is greater than allcount then remove all class='post' element after 3 element $('.immagine-album:nth-child(3)').nextAll('.post').remove(); // Reset the value of row $("#row").val(0); // Change the text and background $('.carica-altro-blogs').text("Carica altro"); }, 2000); } });