Search code examples
javascriptjqueryclickstoppropagation

How to stop function propagation after first click with jQuery


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();
});

Solution

  • 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){