0

I have some click function... whole action is fine but if i fastly doubleclick at call button some elements generates two times. Can you tell me how to stop function propagation after first click? Much thx for help, and this is my code:

$('#start_panel ul li').click(function(event){
    if($(this).hasClass('eng')){
       ...
    }
    else if($(this).hasClass('ger')){
       ...
    }
    else if($(this).hasClass('pln')){
       ...
    }
    event.stopPropagation();
});
David Hoerster
  • 28,421
  • 8
  • 67
  • 102
Lukas
  • 7,384
  • 20
  • 72
  • 127

5 Answers5

3
var clicked = false;
$('#start_panel ul li').click(function(event){
   if (clicked) return;
   clicked = true;

Or use the one function (slightly different : now only one click per li element will be handled) :

 $('#start_panel ul li').one('click', function(event){
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
0

Try this instead:

var myClicker = function(event){
    var self = event.currentTarget;
    if($(self).hasClass('eng')){
       ...
    }
    else if($(self).hasClass('ger')){
       ...
    }
    else if($(self).hasClass('pln')){
       ...
    }
    $(self).one('click', myClicker);
});
$('#start_panel ul li').one('click', myClicker);
sajawikio
  • 1,516
  • 7
  • 12
0
 var i=0;
$('#start_panel ul li').click(function(event){
 if(i==1){
  i=0;
 return false;
  }
if($(this).hasClass('eng')){
   ...
}
else if($(this).hasClass('ger')){
   ...
}
else if($(this).hasClass('pln')){
   ...
}
 i++;


 });
Sora
  • 2,465
  • 18
  • 73
  • 146
0

To clear previous request use Stop(true,true)

$('#start_panel ul li').stop(true,true).click(function(event){
    if($(this).hasClass('eng')){
        ...
    }
    else if($(this).hasClass('ger')){
       ...
    }
    else if($(this).hasClass('pln')){
       ...
    }
    event.stopPropagation();
});
GajendraSinghParihar
  • 9,051
  • 11
  • 36
  • 64
0

You can unbind the click event after the first click:

$('#start_panel ul li').click(function(event){
    $(this).unbind('click'); 
    if($(this).hasClass('eng')){
       ...
    }
    else if($(this).hasClass('ger')){
       ...
    }
    else if($(this).hasClass('pln')){
       ...
    }
    event.stopPropagation();
});
gabitzish
  • 9,535
  • 7
  • 44
  • 65