/html-dom /Basic
GitHub 4932★

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
});

See also

Follow me on and to get more useful contents.