Limiting event execution and listening to events

Asked

Viewed 53 times

0

I need to limit the number of times a button is clicked, below the code of it

    $(".add-produtos").on("click", function(){
    for(var z = 0; z < 17; z++) {
        var testar = produtoObj(i++); //produtoObj é o objeto que renderiza os proddutos na tela, se for necessario posta-lo me falem.
        testar.renderiza();
    };
});

And also wanted to know how do I load more products they have attached to them the function below

        function addCarrinho(){
        var total = 0;

        $("#circulo").html(total);

        $(".material-icons").on("click",function(){
            var soma = total++;
            console.log(soma);
            var somado = soma.toString();
            console.log(somado);
            $("#circulo").html(total);
        });
    }
  • 1

    Can you explain better? 1- "limit the number of times a button is clicked" is to avoid clicks too fast or there is a maximum click limit that depends on another variable? 2- I think you want to use delegation, which means switching to $(document).on("click", ".material-icons", function(){ but it would be interesting to see more code to be sure. For example: where it comes from total?

  • 1- It’s so you can only call the function once. <br> In order to get a better look at the code, I am sending the link from the repository to github https://github.com/victorhcosta/get-devs

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.