0
Hello! My question is this: I would like that each time you click on the button, add one more to my badge, here is the code:
HTML: <button id="buttonAdd"type="button"></button>
HTML badge (where the change will be made):
<a href="pagamentos.html"><i class="fas fa-shopping-cart"></i><span class="badge badge-success"
id="carrinhoIndex">?</span></a>
JS:
var count = 0;
$('#buttonAdd').click(function(){
alert(count);
count++;
});
Apparently the code is right, but it doesn’t work. The version I’m using of bootstrap and javascript got on the bootstrap site, so I don’t know what the problem is (another javascript functionality works)
The Alert there is to check if the code is working, but it is not.
I tried using the function:
HTML: onclick="Acrescentar()";
var cont=0;
function Acrescentar() {
$("#carrinhoIndex").text(cont);
cont++;;
}
And it worked, but it doesn’t add up to +1 every time you click.
Jquery, Bootstrap and Javascript version:
JQUERY:
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
BOOTSTRAP:
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
JAVASCRIPT:
<script src="js/js.js"></script>
Your example worked, thank you very much!
– WesLipe
You’re welcome! Could you mark my answer as the correct answer? Thanks.
– Fabiano Salles