Change font color of a cell Table with ajax

2

Let's say I have the following table:

IhaveanoptionthatIclicktoactivatetheusersselectedbycheckboxes.Everythingalreadyworkingandevenoccurstheactivationofusers.I'musingAjaxbyhavingthebrowsercommunicatewiththeserverandactivatetheuserwithouthavingtoloadthewholepageagain.Myonlyquestionisthis:AftertheuserisactiveIwanttochangethecheckedcelloftheStatusfieldto:ActiveandColorGreen.Would?

IalreadydidsomethingwithaddClass('Ativo')butIonlymanagedtoleaveallthewordsonthelineingreen.Iwouldlikeonlythecelltochangetoactiveandgreen.

FornowIhavethisinmycode:

$('i.icon-check').closest('li').click(fnAtivar);functionfnAtivar(){varparaAtivar=$('#tableUsuariotrinput:checkbox:checked').map(function(){return{cod_user:this.value,tr:$(this).closest('tr').get()}});$.ajax({url:"ativarUsuario.php",
        type: 'post',
        data: {
            codigosAtivar: paraAtivar.map(function () {
                return this.cod_user
            }).get()
        },
        success: function (resposta) {
        resposta = JSON.parse(resposta);
         console.log(resposta, typeof resposta, typeof resposta[0], resposta[1]);
        if (resposta[0]) paraAtivar.each(function(){
            //aqui acredito que vai o código para realizar a alteração
        });
        alert(resposta[1]);
    }
    });
}
    
asked by anonymous 06.11.2014 / 19:10

1 answer

2

Try this:

if (resposta[0]) {
      var tabela = $('#tableUsuario tr');

      $.each(tabela, function(index, tr) {
        var checkbox = $(tr).find("input:checkbox");
        if ($(checkbox).is(':checked')) {
          $(tr).find(".status").text("Ativado");
          $(tr).find(".status").css("color", "#51A351");
        } else {
          $(tr).find(".status").text("Inativo");
          $(tr).find(".status").css("color", "#BD362F");
        }
      });
    }

Remember that in every td that has the status, it should have the class class='status'

    
06.11.2014 / 19:58