JQUERY as add tag p

0

I'm new to JQuery and would like to know how I add two <p> tags without input, for example:

<p>Valor do Pedido: <span  id="resultado" class="resultado">5</span></p>
<p>Taxa de Entrega: <span id="txa"  class="txa">5</span></p>
<p>Total: <span id="tot" class="tot"></span></p>

I would like to add these two values: value + rate = total , but JQuery only recognizes when I use input, and that was not quite what I wanted to use.     

asked by anonymous 11.05.2017 / 11:37

1 answer

1

Try this:

$(document).ready(function(){
  var valor = $("#valor").text();
  var taxa = $("#txa").text();
  var total = Number(valor) + Number(taxa);
  $("#tot").text(total);
});
<p>Valor do Pedido: <span  id="valor" class="valor">5</span></p>
<p>Taxa de Entrega: <span id="txa"  class="txa">5</span></p>
<p>Total: <span id="tot" class="tot"></span></p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
    
11.05.2017 / 11:57