Skip to content

Instantly share code, notes, and snippets.

@hardikpandya
Last active August 29, 2015 14:12
Show Gist options
  • Save hardikpandya/97c08b80f9451aaf4354 to your computer and use it in GitHub Desktop.
Save hardikpandya/97c08b80f9451aaf4354 to your computer and use it in GitHub Desktop.
Interactive Download Button using jQuery
var $button = $("a.download-button"); //finding the matching buttons on the DOM
$button.on('click', function(){ // adding click event handler to the buttons
var $clickedButton = $(this); // storing the current button for reference
var $href = $(this).attr("href");
$clickedButton.text("Downloading...");
$clickedButton.css("background-color", "#275AB0");
setTimeout(function(){
$clickedButton.removeAttr("href"); // remove href so further clicks don't trigger download
}, 50);
setTimeout(function(){
$clickedButton.text("Downloaded.");
$clickedButton.css("background-color", "#aaa");
}, 1500); // this executes 1.5 seconds after click event
$clickedButton.off(); // remove the event listener to disable further clicks
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment