0
I have several Ivs with same class and different values. I wanted to select all of them, take each one’s value and add HTML to each with new values. With the code I made, I can take the value, turn it into an integer, divide it by 600 and add the html I want. But I can only do it for the first div. Someone can help?
$(document).ready(function() {
$wrapper = document.querySelector('.preco-promocional'),
precoTOTAL = $wrapper.innerHTML;
var s3 = precoTOTAL.replace(/[\D]+/g,'');
var valor = parseInt(s3);
var garrafa = valor / 600;
HTMLNovo = '<div style=" color:#4b1472; font-size:11px;">Preço para 6 unidades<br>Cada garrafa por R$ '+garrafa+',00</div>';
$wrapper.insertAdjacentHTML('beforeend', HTMLNovo);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="preco-promocional">R$ 1.500,00</div>
<div class="preco-promocional">R$ 2.500,00</div>
<div class="preco-promocional">R$ 3.500,00</div>
cfgallo, welcome to Stack Overflow in English. Start here for an overview of the site. https://answall.com/tour
– user60252