13 Sept 2016

How Capture Left, Right and Middle Mouse Click with jQuery

$('body').mousedown(function(event) {
    switch (event.which) {
        case 1:
            alert('Left Mouse button clicked.');
            break;
        case 2:
            alert('Middle Mouse button clicked.');
            break;
        case 3:
            alert('Right Mouse button clicked.');
            break;
        default:
            alert('You have a strange Mouse!');
    }
});





Reference:
http://api.jquery.com/event.which/
http://www.w3schools.com/jsref/event_button.asp
http://stackoverflow.com/questions/1206203/how-to-distinguish-between-left-and-right-mouse-click-with-jquery