dynamic download filename
HTML
<button>Set url and download name for anchor</button>
<a href="" data-download="">Download Google logo</a>
JavaScript
var googleLogoURL = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
$('button').on('click', function(){
alert("url and filename set");
$('a').attr({
'href': googleLogoURL,
'data-download': "google-logo.png"
}).text("google-logo.png")
});