jQuery detects left and right mouse clicks

  • 2020-05-16 06:25:00
  • OfStack

The example in this article describes how jQuery detects left and right mouse clicks. Share with you for your reference. The specific analysis is as follows:

This code USES jQuery to detect the left mouse button and the right mouse click, and can determine whether the user has clicked the left mouse button or the right mouse button, which takes into account the abnormal situation of IE, so please feel free to use it.

$("#someelement").live('click', function(e) {
    if((!$.browser.msie && e.button == 0) || ($.browser.msie && e.button == 1))
    {
        alert("Left Mouse Button Clicked,//www.ofstack.com");
    }else if(e.button == 2) {
        alert("Right Mouse Button Clicked,//www.ofstack.com");
    }
});

I hope this article has been helpful to your jQuery programming.


Related articles: