JQuery mouseup function only on left mouse button?

I have this element, which is animated in the mouseup function, but right now it works with both left and right buttons. Is there a way to use the button on the left ?

 $(document).ready(function() { $("div").mouseup(function() { top: "-101%" }); }); 
+6
source share
1 answer

You can check which mouse button was pressed using e.which ( 1 is primary, 2 is middle, and 3 is secondary):

 $(document).ready(function() { $("div").mouseup(function(e) { if (e.which != 1) return false; // Stops all non-left-clicks ... }); }); 
+12
source

All Articles