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>

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