tags:

views:

43

answers:

1

I have two overlapping div elements in my web app.

On the underlying div an event is registered on double click.

On the div that lies above the other div a event is registered on click that hides the div.

The problem is that if I double click on the above div element it is hidden after the first click BUT the second click causes the double click event on the underlying div to fire - how can I prevent that?

+1  A: 

Mixing "click" and "double-click" is going to be problematic at best. However, in this case things might get better if you just ensure that your handler for the "click" event (the event that hides the element) returns false to the browser.

How to do that depends on how your handler is registered. If it's like this:

<div onclick='hideMe();'>

then you'd change that to

<div onclick='hideMe(); return false'>

If you're using some framework or some other means of attaching the handler, then just having the handler function return false should do it.

Pointy
If return false doesn't do it, then something like this should help (in the body of the handler): if (e } else if (window.event }
Ryan Kinal
Yes, @Ryan, that's true, but I've never had an issue with simply returning false. Now, it's true that you can get more control with things like "preventDefault()", and sometimes that's very important.
Pointy
I tried both solutions (I already returned false in the listener) but it did not solve the problem.The problem is not that one event gets published to far. There are two events: the onclick and the ondblclick ... I want to prevent the ondblclick to be fired
Thomas Einwaller
I think what Pointy is suggesting is that you add an ondblclick to the one that you have an onclick for, and in the ondblclick handler, return false or preventDefault.
Ryan Kinal
Well as I said, trying to mix "click" and "double-click" is really not a good idea; it's a situation not handled well by any browser.
Pointy