Event objects

You can pass an argument as an event object to the event handler functions. This object gives us additional information about the event.

For example, if we want to know which mouse button was pressed, we can look at the event object's which property.

<button>Click me any way you want</button>

<script>
var button = document.querySelector("button");
button.addEventListener("mousedown", function(event) {
    if (event.which == 1)
        console.log("Leftbutton");
    else if (event.which == 2)
        console.log("Middlebutton");
    else if (event.which == 3)
        console.log("Rightbutton");
});
</script>
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +