Note: Not supported in all browsers.
I was looking for a way to download a file using jquery without having to set the file url in the href attribute from the beginning.
jQuery('', {
id: 'downloadFile',
href: 'http://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png',
style: 'display:hidden;',
download: ''
}).appendTo('body');
$("#downloadFile")[0].click();