I have this code:
var tudo=0;
function muda(a){
o=$("#"+a).attr("data-ocupado");
var t = $("#gasto").html();
if(o==1){
alert("Lugar já Ocupado!");
}else{
p=$("#"+a).attr("data-preco");
var confirma = confirm("Deseja alugar este lugar? \n Preço: "+p+"€");
if(confirma == true){
tudo = parseInt(p+t);
alert(p);
$("#"+a).attr("data-ocupado", "1");
$('#'+a).css({
'color': 'red'
});
$("#gasto").html(tudo)
}
}
}
With this html and php
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
<div>
<?php
$a=0;
while($a<300){
$a++;
if($a%5==0){
$vazio=" ";
}else{
$vazio="";
}
if($a%50==0){
$extra ="<br>";
}else{
$extra="";
}
$preco=rand(0, 40);
?>
<span style="background-color:silver;color:black;cursor:pointer;" data-ocupado="0" data-preco="<?=$preco; ?>" id="<?=$a; ?>" onclick="muda(<?=$a; ?>)"><i class="fa fa-user"></i></span><?=$vazio; ?><?=$extra; ?>
<?php } ?>
</div>
But whenever I load another icon, I was supposed to increase the price to all the other prices that I had loaded before, but instead, add the values extensively in the div with id="spent"