Geeks With Blogs
Łukasz Kuryło's blog

This is very easy to check, which mouse button was pressed using jQuery.

 

This solution works propertly on IE (tested on 9), Firefox (tested on 4), Chrome. In Opera there doesn't work the middle button

and the browser context menu is showing.

 

$('#someElement').mousedown(function(e) {
    switch (e.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('Unsupported mouse button');
    }
});
Posted on Thursday, May 26, 2011 7:15 PM jQuery | Back to top


Comments on this post: [jQuery] Determine which mouse button was pressed

Comments are closed.
Comments have been closed on this topic.
Copyright © Łukasz Kuryło | Powered by: GeeksWithBlogs.net