I would like to do two things:
- One that
label
with idcnt
, when you press the plus button, add 1 more and when you press the minus button, subtract minus 1. - Otherwise, when
label
cnt
was equal to zero, remove classpizzaselecionada
.
Make the class change if label=#cnt
is equal to 0
<script>
$(document).ready(function(e) {
var Total = parseFloat('0');
var P = $('.pizzadisponivel label').attr('value');
var Pp = (P.replace(/,/,'.'));
var cn = parseFloat('0');
$('#mais').click(function(e) {
$('li').hasClass('pizzadisponivel');
$('li').removeClass('pizzadisponivel');
$('li').addClass('pizzaselecionada');
Total += parseFloat(Pp);
$("#teste").html('R$' + parseFloat(Total).toFixed(2));
alert(Total)
});
$('#menos').click(function(e) {
if ($('label #cnt').){
$('li').hasClass('pizzaselecionada');
$('li').removeClass('pizzaselecionada');
$('li').addClass('pizzadisponivel');
}
else {Total -= parseFloat(Pp);
$("#teste").html('R$' + parseFloat(Total).toFixed(2));
alert(Total);
}
});
});
</script>
</head>
<body>
<div>
<li class="pizzadisponivel"><label value="29,90">29,90</label></li>
<button id="mais">mais</button>
<button id="menos">menos</button>
<label id="cnt">0</label>
<label id="teste">R$0,00</label>
</div>
</body>
</html>