Why on long press the alert doesn't "fire" and show alert "button", just this one word being an ID? I want to use vanilla js. Here can be an possible answer, but I do not know how to add combine it with a code below?
onClick to get the ID of the clicked button
Currently the returned message is "Uncaught ReferenceError: clicked_id is not defined at HTMLButtonElement.".
I know how to make it work for one button, writing here
var button = document.getElementById(button);
What I am trying to do and failing is to make it work for several various buttons and being activated based on clicked_id.
<button id="button">click</button>
<script>
(function(window, document, undefined){
'use strict';
var start;
var end;
var delta;
var button = document.getElementById(clicked_id);
button.addEventListener("mousedown", function(){
start = new Date();
});
button.addEventListener("mouseup", function() {
end = new Date();
delta = end - start;
if (delta > 0 && delta < 500) {
alert("less than half second:");
}
if (delta > 500 && delta < 1000) {
alert("more than half second and less than a second:");
}
if (delta > 1000) {
alert(this_id);
}
});
})(window, document);
</script>