ondblclick and onclick together

F

Fred Oz

Dan said:
How do I catch both ondblclick and onclick on a div?

By putting both events on the div - trivial example:

<div onclick="document.getElementById('cc').innerHTML = 'You clicked';"
ondblclick="document.getElementById('cc').innerHTML =
'<b>you double clicked</b>';">the result: <span id="cc"></span></div>

However, the first click will execute the "onclick", so if the double
click gets through (as it does in my example) both events will fire
unless the first click does something that immediately causes all
further input to be ignored - say opening a modal dialog like alert.

I can't think of how a double click could get through before the first
single click - but I'm happy to be enlightened.

Fred.
 
D

Daniel Kirsch

Fred said:
I can't think of how a double click could get through before the first
single click - but I'm happy to be enlightened.

You my start a timer on a single click which calls the method to be
executed on a single click. The doubleclick handler should cancel the
singleclick timer (if not allready done) and than call the double click
action.

However, this means that every single click action will be a bit delayed.

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top