JSFiddle - React, Tailwind, and code Playground
HTML
<a href="downloadFile.zip" id="download" class="button">Download the file...</a>
<button id="btn">click</button>
CSS
.button {
background-color: #ddcccc;
border: 1px solid black;
color: black;
font-family: Arial;
font-size: small;
text-decoration: none;
padding: 3px;
}
JavaScript
var downloadButton = document.getElementById("download");
var counter = 10;
var newElement = document.createElement("p");
newElement.innerHTML = "10 sec";
var id;
downloadButton.parentNode.replaceChild(newElement, downloadButton);
function startDownload() {
this.style.display = 'none';
id = setInterval(function () {
counter--;
if (counter < 0) {
newElement.parentNode.replaceChild(downloadButton, newElement);
clearInterval(id);
} else {
newElement.innerHTML = +counter.toString() + " second.";
}
}, 1000);
};
var clickbtn = document.getElementById("btn");
clickbtn.onclick = startDownload;