Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
93
rated 0 times [  98] [ 5]  / answers: 1 / hits: 39046  / 12 Years ago, mon, february 11, 2013, 12:00:00

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


More From » jquery

 Answers
9

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.


[#80305] Saturday, February 9, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devonw

Total Points: 311
Total Questions: 116
Total Answers: 111

Location: Senegal
Member since Fri, Aug 21, 2020
4 Years ago
;