tags:

views:

873

answers:

2

in jquery is there a way to distinguish left and right clicks ?

+6  A: 

You can try this plugin JQuery right click

Alexey Ogarkov
+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
The jQuery plugin linked above is using `e.button==2` instead.
ceejayoz
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
i found that contextmenu did the trick as well.
dingdingding
@Russ Thanks for the explanation!
ceejayoz