37/121

Distinguish between left and right mouse clicks

The mousedown and mouseup event handlers let us know which mouse button is clicked:

ele.addEventListener('mousedown', function(e) {
    // e.button === 0: the left button is clicked
    // e.button === 1: the middle button is clicked
    // e.button === 2: the right button is clicked
    // e.button === 3: the `Browser Back` button is clicked
    // e.button === 4: the `Browser Forward` button is clicked
});

Might be useful