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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With