I have a simple code like in below snippet to have alert whenever a button is clicked and alert is shown, that runs alright but with certain drawbacks (know that this is how setTimeout works).
Here when you click button 2,3,4 times , than alert is shown that many times only. But I want alert only 1 time which is called from 1st click and ignore further clicks until 3 second are complete for 1st click.
function alertBtn() {
setTimeout(alertFunc, 3000);
}
function alertFunc() {
alert("Alert is clicked so remain alerted");
}
<button onclick="alertBtn()">Alert me</button>
Is it possible with pure JavaScript way? It's may be similar to method that SO uses like we can't comment again within 5s(or something), the button is kinda disabled for that time interval. Kind of barrier for 5sec