Forum Moderators: open

Message Too Old, No Replies

Differentiate Single & Double Click

         

almo136

1:40 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



Hi,

Is it possible to differentiate single click and double click using javascript/jquery?

Ie: If a user single clicks an element Action A takes place and if they double click the element Action B takes place?

Thanks.

whoisgregg

7:42 pm on Jul 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi almo!

You can use the ondblclick event, just be careful with defining both a regular single onclick and an ondblclick event as I believe the onclick event also fires whenever the ondblclick fires.

almo136

8:16 pm on Jul 8, 2009 (gmt 0)

10+ Year Member



Thanks. I used the ondblclick method and it works.

You are right about the single click still firing. Is it possible to prevet this? This is what i've got so far:

<li class="directory expanded" ondblclick="javascript:window.location.href="http://example.com";">

whoisgregg

12:54 pm on Jul 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't know of a way to block the single click event. In my brief research on the subject it seemed like a problem that no one had solved -- at least not in a portable way.