:::: MENU ::::
Posts tagged with: jQuery

How to detect left mouse click and right mouse click with jQuery

If you want to implement a javascript interface probably you will get to a point where you have to know witch button was pressed. The next code will detect correctly for IE, Firefox, Chrome, Opera and Safari.


/* this will append click detection to whole document
 * if you want to add this feature just on one area
 * just change the selector for the jQuery
 */
jQuery(document).click(function(event) {
   if (jQuery.browser.msie){
      if (event.which < 2){
         alert('Left button');
      }
   }else
   switch (event.which) {
      case 1:
         alert('Left button');
         break;
      case 2:
         alert('Middle button');
         break;
      case 3:
         alert('Right button');
         break;
      default:
         alert('unknown');
   }

});

Continue Reading