Languages

JavaScript - how mouse buttons are numbered for onclick event when is use event which property?

3 points
Asked by:
Adnaan-Robin
724

How the buttons on the mouse are numbered for the onclick event in JavaScript when is use event which property?

My source code:

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
    Answered by:
    Admin Dirask Community
    4380

    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

    1. UIEvent.which - MDN Docs 
    0 commentsAdd comment
    Donate to Dirask
    Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
    Join to our subscribers to be up to date with content, news and offers.
    Native Advertising
    🚀
    Get your tech brand or product in front of software developers.
    For more information Contact us
    Dirask - we help you to
    solve coding problems.
    Ask question.

    ❤️💻 🙂

    Join