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?
– Leandro Angelo
How you are handling the click event (what calls the function)?
– Renato Diniz
It’s not just doing
$('#botao').off('click').on('click', clickHandler);
? At the time of registeringclickHandler()
?– Marcelo Shiniti Uchimura
Always when the user clicks on a button once the event and fired twice, yesterday I canceled almost 1000 nf because of this :(
– Guilhermezio
I’m doing like this
$('#div').off().on('click','#botao');
– Guilhermezio
What is the
#botao
in.on('click', '#botao')
?– Marcelo Shiniti Uchimura
@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(); 
 });
– Guilhermezio
You are removing the events in
#divEmitirCTE
and then put on#btnEmitirCTE
! Why don’t you$('#btnEmitirCTE').off('click').on('click', function (event) { ... });
?– Marcelo Shiniti Uchimura
If in one click the "event" fires twice you must be making the bind more than once
– Leandro Angelo
@Marcelouchimura the
off()
is executed before theon()
?– Guilhermezio
@Guilhermezio, yes, in the order they appear, in the call
– Marcelo Shiniti Uchimura
@Marcelouchimura as then he removes the event added in
on()
– Guilhermezio
@Guillhermezio, the
off(type)
withdraw (undo the Binding) any event of the kindtype
– Marcelo Shiniti Uchimura
http://api.jquery.com/off/
– Marcelo Shiniti Uchimura
bind
andunbind
oron
andoff
is to complicate unnecessarily. It would be better to do theon
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– Isac