Android longpress

Example that works on all Windows and Linux browsers, but seems to lose mouseup events on all Android browsers.

by wanderinglogic

HTML

<a id="btn"></a>

CSS

#btn {
    user-select: none;
    -moz-user-select:none;
    -webkit-user-select:none;
    touch-callout: none;
    -moz-touch-callout: none;
    -webkit-touch-callout: none;
    text-align: center;
    font-size: 2em;
    border-style: solid;
    border-width: 3px;
    cursor: pointer;
}

JavaScript

var outVal = "a";
var btn = document.getElementById('btn');
var myTimer;
btn.textContent = 'pressMe: ';
btn.addEventListener("mousedown", function(){
   myTimer = setTimeout(function(){
     btn.textContent += "t";
     outVal = "b";
   }, 500);
});
btn.addEventListener("mouseup", function(){
   clearTimeout(myTimer);
   btn.textContent += outVal;
   outVal = "a"
});