I'm trying to redirect this button after specific time. But the countdown couldn't start before redirecting. I wish it to be redirect after 5 or 10 seconds. But remember window.location should be in HTML Element.
function myFunction(){
var button=document.getElementById('button');
button.addEventListener('click', function(){
var i=0;
var tt=setInterval(function (){
i=i+1;
var counter=5-i;
button.innerHTML='You Will Be Redirect After:'+counter;
if(counter===0){
clearInterval(tt);
}
},1000);
});};
<button id="button">
<a href="#" class="butstyle" id="button1" onclick="myFunction(window.location='https://google.com')" >Click To Redirect</a>
</button>