Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single click triggered on a double click [duplicate]

Possible Duplicate:
Need to cancel click/mouseup events when double-click event detected

I am trying to get a HTML object to behave differently when a single or double click event happens.

Currently with my working example http://jsfiddle.net/9vvEG/ the single click is triggered on the double click, I wish for my code to listen exclusively for the event pre-configured. i.e. if double clicked ignore single click and vice versa.

No success as of yet, but if you click my example link above you can see the error in progress.

like image 924
Xavier Avatar asked Aug 19 '11 09:08

Xavier


1 Answers

From the jQuery docs on dblclick:

It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable.

It seems that there is going to be no reliable way to determine whether the user intended a double click or two single clicks, but if you want to try, you could perhaps use setTimeout in a click event handler to see if another click occurs within a certain period of time.

like image 76
James Allardice Avatar answered Nov 09 '22 20:11

James Allardice