Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between 'mouseup' and 'click' events?

Using jQuery, I often like to use mousedown and mouseup events in conjunction for pushable buttons.

However, in every case I've used the mouseup event, binding the click event instead seemed to produce identical results.

Is there any substantial difference between the two methods below?

// Method 1 $('.myButton').bind('click', callback);  // Method 2 $('.myButton').bind('mouseup', callback); 

Please note I'm seeking a technical explanation on the differences between using both methods. This has no relation to the question that has been flagged as a dupe: Differentiate click vs mousedown/mouseup

like image 686
caiosm1005 Avatar asked Feb 11 '13 02:02

caiosm1005


People also ask

What is a mouseup event?

The mouseup event is fired at an Element when a button on a pointing device (such as a mouse or trackpad) is released while the pointer is located inside it. mouseup events are the counterpoint to mousedown events.

Does mouseup fire before click?

Mouseup is always firing before click, despite this order.

What is the difference between mouseup and Mousedown?

MouseDown occurs when the user presses the mouse button; MouseUp occurs when the user releases the mouse button.

What is a click event?

An element receives a click event when a pointing device button (such as a mouse's primary mouse button) is both pressed and released while the pointer is located inside the element.


1 Answers

With a mouseup event, you can click somewhere else on the screen, hold down the click button, and move the pointer to your mouseup element, and then release the mouse pointer.

A click event requires the mousedown and mouseup event to happen on that element.

The normal expectation is that a click requires both the mousedown and mouseup event, so I'd recommend the click event.

From the possible duplicate, it appears that mouseup and mousedown events can also be caused by mouse buttons other than the left click button. Which is very different from what a generic user would expect.

like image 55
Bill Lynch Avatar answered Sep 22 '22 12:09

Bill Lynch