Is there a way to disable the mousedown event once a specific condition is met?
For instance, in the code below, how can I prevent the Key and event from functioning when the temp
reaches 30
$(document).ready(function() {
var temp = 0;
var to = null;
var iv = null;
$("#ClickMe").on("mousedown", function() {
temp++;
$("#Temp").html(temp);
to = setTimeout(function() {
iv = setInterval(function() {
temp++;
$("#Temp").html(temp);
}, 75);
}, 500);
}).on("mouseup mouseleave", function() {
clearTimeout(to);
clearInterval(iv);
});
});
div {
margin: 10px;
padding: 26px;
background-color: yellow;
text-align: center;
border-radius: 10px;
max-width: 40px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="ClickMe">CLICK ME</button>
<div id="Temp">0</div>