Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind to right-click with jQuery?

I want to bind a function to a right click. Is this possible with jQuery UI?

like image 847
kenwarner Avatar asked Oct 09 '11 21:10

kenwarner


2 Answers

though not listed on http://api.jquery.com/bind/, the 'contextmenu' event seems to work

$('.rightclickable').bind('contextmenu', function() {
    // right-click!
});
like image 96
kenwarner Avatar answered Oct 13 '22 06:10

kenwarner


Not directly, but you can check which mouse button was pressed in a normal mousedown event handler, with the which property of the event object:

$("#someElem").mousedown(function(e) {
    if(e.which == 3) {
        //Right click!
    }
});

Here's a working example of the above.

like image 36
James Allardice Avatar answered Oct 13 '22 05:10

James Allardice