views:

43

answers:

2

Hi! If I subscribe dblclick() and click() for a DIV element and make double click by mouse on the DIV, the click() handler calls first before dblclick() is called. How to avoid handling click() before the dblclick()?

UPDATE: The question has already asked before Prevent click event from firing when dblclick event fires. But here are good answers too.

+2  A: 

Probably not the best way to do it: You could set a timeout in the click handler function and clear the timeout in the doubleclick handler function.

The timeout could call a function that will impliment what you really want to happen onClick and that way you can have your dblclick() function handle what happens when the users double clicks.

theycallmemorty
Agreed, this is the only way to do this. OP should note that the jQuery docs mention that it's inadvisable to bind click and dblclick handlers to a single element. http://api.jquery.com/dblclick/
Aaron
+2  A: 

Try this: http://jsfiddle.net/DAgyC/ It implements an timeout after the first click, if there is a double-click, the first click is ignored.

chriszero
Thanks for the example.
Desperadeus