JSFiddle - React, Tailwind, and code Playground

HTML

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/magnific-popup.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.0.0/jquery.magnific-popup.js"></script>
<div class="square click">
</div>
<div class="square mousedown">
</div>

CSS

.square {
    height: 20px;
    width: 20px;
}

.click {
    background-color: red;
}

.mousedown {
    background-color: blue;
}

JavaScript

var select = function(event){
    console.log(event);
    if(event.button === 0){
         // Code that's working fine
    }
    else if(event.button === 2){
        alert("hello");
    }
}

document.getElementsByClassName('click')[0].addEventListener('click' ,select,false);

document.getElementsByClassName('mousedown')[0].addEventListener('mousedown' ,select,false);