0
Hello guys I’m creating this script to check the largest number and apply it as discount, but I’m having trouble identifying the largest number and do the calculation.
Doubt is how to take 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>
<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>
<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>
Do you have access to HTML to the point where you can change it? If so, it makes more sense for you to add an attribute to the tags
p
:<p data-percentual="18.97">...</p>
– Uilque Messias
@Uilque Messias I don’t have access, this is generated from a system so I have to work with that same.
– Steve Angello