4

i am having a problem when i click on an input(button) (click event captured using jquery) it is executed two times but the click event is single... i used "e.stopPropagation();" - but it didn't work...

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

i need the reason and the solution...

take care..

3
  • 1
    post your code...so that we can understand whats going on... Commented Dec 28, 2010 at 7:23
  • May be you somehow ran this click-setup code twice? Commented Dec 28, 2010 at 8:06
  • @maksymko... no brother just once.. Commented Dec 28, 2010 at 8:14

5 Answers 5

10

problem is 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..

Sign up to request clarification or add additional context in comments.

Comments

4

Please use e.stop(true,true) and function which you are using. like

e.stop(true,true).show();

2 Comments

well i am getting an error.. which says that e.stop(true,true) is not a function... :(
if you are other work on another element then please use that element with stop function. like we wanna show any hidden div on button click then $('#ok').click(function(){ $('div').stop(true,true).show();});. Please let me know the process.
3

I think you use this code as below:

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

});

Comments

1

e.preventDefault() is likely what you are looking for.

Comments

0

i used

return false;

after the desired action.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.