Text-based counter inside cells in a table

1

I have a table updated by Ajax and I receive different values in some cells. I want to do an accountant if some values match. I have a function that does it but the counter does not show the new value until I refresh the entire page. What I can do? I appreciate your help and time guys.

This is my function:

var consCount = 0;
$(function() {
$("#pizarra #trPizarra").each(function(){
    var estado = $(this).find('#tdEdo').text();
    var asunto = $(this).find('#tdImg').text();
    var juntos = estado + asunto;

if(juntos === "listo" + "0" || juntos === "listo" + "4"){ ++consCount; }
});

setInterval(function(){    
$('#count-consulta-span').load(document.URL +  ' #count-consulta-span',function(){
    $('#count-consulta-span').text(consCount);
        });
},3500);
});
    
asked by Emm 03.12.2016 в 09:38
source

1 answer

0

Error:

  

You execute the script counter, only in the onload .

Solution:

You could create a function ( contador ) and call it each time the table is updated.

For example:

$(function() {

  function contador() {
    var consCount = 0;
    $("#pizarra #trPizarra").each(function() {
      var estado = $(this).find('#tdEdo').text();
      var asunto = $(this).find('#tdImg').text();
      var juntos = estado + asunto;

      if (juntos === "listo0" || juntos === "listo4") {
        ++consCount;
      }
    });
    return consCount;
   }

  setInterval(function(){
    $('#count-consulta-span').load(document.URL +  ' #count-consulta-span',function(){
      $('#count-consulta-span').text(contador());
    });
  },3500);
});
    
answered by 03.12.2016 в 11:47