JQUERY how to add <p> tag

Asked

Viewed 82 times

0

I’m new to Jquery and would like to know how I add two tags <p> 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, only that Jquery only recognizes when I use input, and that’s not quite what I wanted to use.

1 answer

1


Try it this way:

$(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>

Browser other questions tagged

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