Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Single button click, click event firing two or more times

Tags:

jquery

events

I have HTML input and button elements. I use the buttons to submit forms, open secondary windows, etc. The problem is, a single click is turning into 2 (and sometimes many more) form submissions, or opening two additional browser windows. I've reproduced the problem in multiple web browsers. I've tried switching jQuery versions and that didn't change anything. What could be causing this sort of thing to happen?

like image 935
gholmes Avatar asked Jan 24 '10 18:01

gholmes


1 Answers

Your problem may be happening because you are assigning the same handler to the click event multiple times. I suggest you check that the line where you assign the handler is not being called multiple times inadvertently. Another solution could be a call to unbind (deprecated 3.0) or off (superseeded) first:

$("#myButton").unbind("click").click(myHandler); // deprecated $("#myButton").off("click").click(myHandler); // superseeded 

But without seeing some code I'm just guessing.

like image 149
Darko Z Avatar answered Sep 29 '22 18:09

Darko Z