function countDown(idDisplay,counterValue,idBTN){
document.getElementById(idDisplay).textContent = counterValue
if(counterValue !== 0){
counterValue--
document.getElementById(idBTN).setAttribute('disabled','')
setTimeout(function(){
countDown(idDisplay,counterValue,idBTN)
},1000)
} else {
// Enable the button
document.getElementById(idBTN).removeAttribute("disabled")
document.getElementById(idDisplay).textContent = "0"
}
}
countDown('count',6,'btnCounter')
Javascript
Komentar