Good, I have this code
var timer =null;
function interval(){
if (timer != null)
{
clearInterval(timer)
timer = null
}
let elem = document.getElementById("segundos");
elem.textContent="0s!!!";
timer = setInterval(function(){
let elem = document.getElementById("segundos");
elem.textContent="3s!!!";
elem.style.color = "red";
alert('duro mas de 3');
clearInterval(timer);
timer = null;
$('#buscador').val('');
$('#buscador').html('');
},3000);
}
$('#buscador').on('input',function(){
interval();
});
What I want to do is to count the time when a key is pressed, for example if I write in the input: h (it counts for 3 seconds if it takes more than 3 seconds to do something) if it does not exceed 3 seconds then it restarts the account and so on I do not know if I explain myself well, I have no idea how to do it.
I'm ready to update the code, it worked like this