Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Created October 13, 2019 21:15
Show Gist options
  • Save csharpforevermore/14f125d7e63bc1fd2864b6f5ec83e9f2 to your computer and use it in GitHub Desktop.
Save csharpforevermore/14f125d7e63bc1fd2864b6f5ec83e9f2 to your computer and use it in GitHub Desktop.
Get which mouse button was clicked (left, middle or right) using jQuery
$('#element').mousedown(function(event) {
switch (event.which) {
case 1:
alert('Left Mouse button pressed.');
break;
case 2:
alert('Middle Mouse button pressed.');
break;
case 3:
alert('Right Mouse button pressed.');
break;
default:
alert('You have a strange Mouse!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment