in jquery is there a way to distinguish left and right clicks ?
+2
A:
You can easily do tell which mouse button was pressed by checking the which
property of the event object on mouse events
/*
1 = Left Mousebutton
2 = Centre Mousebutton
3 = Right Mousebutton
*/
$([selector]).mousedown(function(e) {
if (e.which === 3) {
/* Right Mousebutton was clicked! */
}
});
Russ Cam
2009-10-29 22:20:25
The jQuery plugin linked above is using `e.button==2` instead.
ceejayoz
2009-10-29 22:33:04
yep. Using `event.button` cross browser is more of a problem than `event.which` as the numbers used for the buttons in `event.button` vary. Take a look at this article from Jan 2009 - http://unixpapa.com/js/mouse.html
Russ Cam
2009-10-29 22:37:36
i found that contextmenu did the trick as well.
dingdingding
2009-10-30 07:06:14
@Russ Thanks for the explanation!
ceejayoz
2009-10-30 12:44:21