Sadesh Kumar N Sadesh Kumar N - 1 year ago 60
Javascript Question

Triggering onclick event using middle click

I am using the

event of a hashed link to open a
as a pop up. But the middle click does not trigger the
but only takes the
attribute value of the link and loads the URL in a new page. How can I use middle click to open the
as a popup?

Answer Source

beggs' answer is correct, but it sounds like you want to prevent the default action of the middle click. In which case, include the following

$("#foo").live('click', function(e) { 
   if( e.which == 2 ) {
      alert("middle button"); 

preventDefault() will stop the default action of the event.