Double execution on one click jquery

I had a problem when I press the enter button (the click button recorded using jquery) is executed twice, but the click event is one ... I used "e.stopPropagation ();" - but it did not work ...

jQuery("#ok").click(function(e){ alert("Alert"); e.stopPropagation(); }); 

I need a reason and a solution ...

take care.

+4
source share
5 answers

problem solved ...

I just added e.stopImmediatePropagation(); to the click function ... and it worked ... None of the following functions worked ...

 e.preventDefault(); e.stopPropagation(); return false 

--------------------- --------------------- CODE

 jQuery("#ok").click(function(e){ alert("Alert"); e.stopImmediatePropagation(); }); 

Click here for more information on jQuery Events ..

+8
source

Use e.stop(true,true) and the function you use. as

 e.stop(true,true).show(); 
+4
source

I think you are using this code as below:

 jQuery("#ok").click(function(){ alert("Alert"); return false; 

});

+3
source

e.preventDefault() you are most likely looking for.

+1
source

I used

 return false; 

after the desired action.

0
source

Source: https://habr.com/ru/post/1333546/


All Articles