Hello everyone, I'm creating this script to check the largest number and apply it as a discount, but I'm having trouble identifying the number greater and make the calculation.
The question is how to get the values with the comma and return the highest value.
$('.item').each(function() {
var item = $(this);
var flag = item.find('.flag');
var value;
//ESTE IF VERIFICA SE TEM MAIS DE 1 FLAG
//QUERO RETORNAR O NUMERO MAIOR COM PONTO OU VIRGULA ENTRE AS 2 FLAGS
if(flag.length > 1){
flag.each(function() {
value = $(this).text().replace(/[^0-9]/g, '');
console.log(value);
});
};
});
*{margin:0;padding:0;list-style:none;font-family:sans-serif;box-sizing:border-box}
ul{display:flex;justify-content:space-around}
.item{padding:10px;width:30%;float:left;border:1px solid #000}
.flag,.console-log{margin:5px 0;padding:5px 0;color:#FFF;text-align:center;background-color:#1485D3}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><ul><liclass="item">
<p class="flag 1897----promo-comprador">18,97% - Promo Comprador</p>
<p class="flag 8131----desconto-no-boleto">8,131% - Desconto no Boleto</p>
<p id="" class="console-log"></p>
</li>
<li class="item">
<p class="flag 1897----promo-comprador">18,97% - Promo Comprador</p>
<p class="flag 8131----desconto-no-boleto">8,131% - Desconto no Boleto</p>
<p id="" class="console-log"></p>
</li>
<li class="item">
<p class="flag 1897----promo-comprador">18,97% - Promo Comprador</p>
<p class="flag 8131----desconto-no-boleto">8,131% - Desconto no Boleto</p>
<p id="" class="console-log"></p>
</li>
</ul>