6

Possible Duplicate:
Jquery: detect if middle or right mouse button is clicked, if so, do this:

How do I show alert box that says "middle mouse button clicked" when I click on text, or any dom element? I want to be able to differentiate between middle mouse and normal right click using jquery/javscript.

I did refer to this: Jquery: detect if middle or right mouse button is clicked, if so, do this:

and modified the js fiddle to this: http://jsfiddle.net/zAGLP/29/

But am seeking an alternative to "live()" function.

Community
  • 1
  • 1
Teivere
  • 317
  • 2
  • 4
  • 13

1 Answers1

15
$(document).bind('mousedown', function(e) { 
   if( (e.which == 1) ) {
     alert("left button");
   }if( (e.which == 3) ) {
     alert("right button");
   }else if( (e.which == 2) ) {
      alert("middle button"); 
   }
   e.preventDefault();
}).bind('contextmenu', function(e){
 e.preventDefault();
});
Mario
  • 2,942
  • 1
  • 25
  • 38