Fill val of a class that is created dynamically

Asked

Viewed 115 times

3

I am making a request, which with this return, I create a class with the return name with the date attribute to be the value I want to perform the calculation.

He gets like this

I won’t put all the requisition that is huge and does not come to the case

dados = $.parseJSON(data);
$.each(dados,function (key) {
      $(".dataImposto").append(" <div class='row static-info align-reverse'> <div class='col-md-8 name '>"+dados[key].nome+" ("+dados[key].valor+"%)</div> <div id='imposto' class='col-md-3 value "+dados[key].nome.replace( /\s/g, '' ) + " ' data-class="+dados[key].nome.replace( /\s/g, '' )+" data-imposto="+dados[key].valor+" > </div> </div>");
});

He begets me as a result of something like

<div class="dataImposto">
  <div class="row static-info align-reverse">
    <div class="col-md-8 name "> DAS(11.50 % )
    </div>
    <div id="imposto" class="col-md-3 value DAS" data-class="DAS" data-imposto="11.50"> </div>
  </div>
  <div class="row static-info align-reverse">
    <div class="col-md-8 name ">Imposto de Renda (15.00%)</div>
    <div id="imposto" class="col-md-3 value ImpostodeRenda" data-class="ImpostodeRenda" data-imposto="15.00">
      </div>
  </div>
</div>

My problem is when I try to write in the generated class Impostoderenda for example, it gives me a return of Undefined

How to solve this?

Edit 1:

 //faz a soma
  valueSubTotal = parseFloat((totalLicenciamentos + totalOpcionais + totalGateways + totalHardwarePag + valUpdate + totalGarantia) - totalSuporte);
  //exibe a soma no formato $0.000,00, não é gerado dinamicamente, aparece         

$(".valueSubTotal").text(parseFloat(valueSubTotal, 10).toFixed(2).replace(/[.]/g, ",").replace(/\d(?=(?:\d{3})+(?:\D|$))/g, "$&.").toString());

  //valor gerado dinamicamente, não aparece
  $(".ImpostodeRenda").attr("data-class", "teste")
  • How are you trying to "write"?

  • It would dynamically take this value, but $(". nameClass"). val(value);

  • Shouldn’t be html() instead of val()?

  • With html() not working $(".Impostoderenda"). html("ddd");

  • @gabrielfalieri The return undefined has nothing to do with the generated class. Most likely some of these variables you use in accounts are undefined because it was not recovered correctly, so you sum up undefined with anything and the result is undefined also. I made a very simple example that illustrates that in general the code works. See here.

  • You can find a simple explanation on how to manipulate dynamic elements at this link: https://answall.com/questions/249005/input-added-com-append-n%C3%A3o-sends-the-data-post/249040#249040

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.