I have a simple type reference

<div id="link"> <a href="/somePage/someMethod?argument=2">Click here</a> </div> 

Is it possible to catch the mouse wheel event on the $ ("# link") element using jquery?

    2 answers 2

    To do this, you just need to catch the mousedown event, and then check in the callback that the event property of the event object is 2 .

     document.querySelector("#link").addEventListener("mousedown", function(event) { if (event.which === 2) { console.log("Middle"); } }); // JQuery, если принципиально $("#link").on("mousedown", function(event) { if (event.which === 2) { console.log("Middle"); } }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

    However, I do not know how this code will behave, for example, on Apple computers, where there is no middle mouse button at all.

    You can also check the button property. But there for the middle mouse button corresponds to the value 1 , and not 2 , as in which .

    • About Apple, I, if anything, wrote that there is a possibility that the values ​​of the buttons "will shift", and 2 will be equal to the right button, for example, which can lead to unpleasant surprises. - smellyshovel
    • And something else. If you use this check to check if the link opens to another tab, then it seems to me that it is better to use some other method. - smellyshovel

    Link to documentation ...

     $("#link").mousedown(function() { console.log(event.which); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="link"> <a href="/somePage/someMethod?argument=2">Click here</a> </div> 

    • one
      the question in question, obviously, is to separate the clicks of the buttons from the wheel. - teran
    • @teran kindergarten of some kind ... Speech from what to catch, but how else and where and why, why, how much and where .... The owner of the question himself decides, not me .... He asked how to catch Here is an example ...)))) - Air
    • one
      The question is how to catch the click of the middle button, namely the middle button, and not any of the three. If you are asked how to catch enter keystrokes on the keyboard, you bare keydown will bring what? - teran
    • one
      @teran, I don’t understand why to be so nervous ....))) Well, I put a minus and everything ... What did the mind teach me to learn?)) Some time ago, there was a conversation that a person should not be given a fish but a fishing rod .. .))) - Air
    • @Air was there :) - Daniel