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?
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?
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 .
2 will be equal to the right button, for example, which can lead to unpleasant surprises. - smellyshovelLink 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> keydown will bring what? - teranSource: https://ru.stackoverflow.com/questions/755505/
All Articles