EN
JavaScript - how mouse buttons are numbered for onclick event when is use event which property?
1 answers
3 points
How the buttons on the mouse are numbered for the onclick
event in JavaScript when is use event
which
property?
My source code:
xxxxxxxxxx
1
2
<html>
3
<body>
4
<button id="my-button">Click me using different buttons!</button>
5
<script>
6
7
var myButton = document.querySelector('#my-button');
8
9
myButton.addEventListener('mousedown', function(e) {
10
console.log('key=' + e.which);
11
});
12
13
</script>
14
</body>
15
</html>
What I have noticed is: 1
- left button, 2
- middle/scroll button, 3
- right button.
Is the order always the same?
1 answer
3 points
Be careful, which
property is non standard (consider to use MouseEvent.button).
Yes, the order should be always the same.
Basic:
0
- no button,1
- left button,2
- middle button (scroll wheel press),3
- right button.
Additionally:
4
- turn scroll wheel up,5
- turn scroll wheel down,6
- push scroll wheel left,7
- push scroll wheel right,8
- 4th button (browser backward button).
References
0 commentsShow commentsAdd comment