views:

95

answers:

3

Hi, I am using jquery 1.3.2.

I am registering two handlers as follows:

$(document).onmousedown(dochandler)

$('#element').click(elemhandler)

When I click on #element both the handlers get called. And surprisingly dochandlers gets called before elemhandler. I have tried changing the orders of above handler registration, but no use.

Both handlers are returning false to avoid event propagation.

My understanding is elemhandler should get called when #element is clicked. Since I am returning false from elemhandler, the dochandler should not be called. And even if dochandler gets called, it shouldn't get called before elemhandler.

Any idea what might be wrong here? Thanks.

+3  A: 

They are two separate events so returning false on one wont affect the other. The click event is fired when the mouse button is released: http://api.jquery.com/click/

poswald
that works. registering elemhandler as onmousedown for #element now.thanks.
Jayesh
A: 

dochandler is called prior elemhandler because mousedown event happens prior click event and as poswald mentioned, they are two separate events and they don't affect each other.

Igor Pavelek
A: 

The click event means the mouse buttons is pressed down and released. The mouseDown is only pushed down. For example if you do drag and drop, the mouseDown event is fired, then any number of mouseMove, and finally mouseUp.

So yes, mouseDown is fired before click. And as others said they are different events so they don't affect each other.

Pierre Henry