Event fired twice in Jquery click

Asked

Viewed 161 times

1

I am on time having problems with jQuery events. I have used all the best practices to stop the double event of click. Following are examples:

.off()
e.preventDefault();
e.stopPropagation();
unbid('click');

Always when there is a click I perform this function

function LoadingTela(botao,tipo) {
     if (tipo == true) {
       $(botao).prop("disabled", true); 
       $('.mask-loading').show(); 
     }else { 
       $(botao).prop("disabled", false); 
       $('.mask-loading').hide(); 
     } 
 }

Has anyone come up with any solution or new event control?

  • did not understand... you work with the event of double click or want to disable the bind after the user click once?

  • How you are handling the click event (what calls the function)?

  • It’s not just doing $('#botao').off('click').on('click', clickHandler);? At the time of registering clickHandler()?

  • Always when the user clicks on a button once the event and fired twice, yesterday I canceled almost 1000 nf because of this :(

  • I’m doing like this $('#div').off().on('click','#botao');

  • What is the #botao in .on('click', '#botao')?

  • @Marcelouchimura to be more exact my code is like this $('#divEmitirCTE').off().on('click', '#btnEmitirCTE' ,function (event) { 
 //aqui faco as verificações e chamo o metodo ajax Algo(); 
 });

  • 1

    You are removing the events in #divEmitirCTE and then put on #btnEmitirCTE! Why don’t you $('#btnEmitirCTE').off('click').on('click', function (event) { ... });?

  • 1

    If in one click the "event" fires twice you must be making the bind more than once

  • @Marcelouchimura the off() is executed before the on() ?

  • @Guilhermezio, yes, in the order they appear, in the call

  • @Marcelouchimura as then he removes the event added in on()

  • @Guillhermezio, the off(type) withdraw (undo the Binding) any event of the kind type

  • http://api.jquery.com/off/

  • bind and unbind or on and off is to complicate unnecessarily. It would be better to do the on based on a above element using the target as selector, thus: $(document).on('click','#botao', function(){...});. This way you have no problem with registering multiple times the click event

Show 10 more comments
No answers

Browser other questions tagged

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