title: add download function to a click event with Javascript
body: <p>I am wondering if it is possible to add a download function to a click event purely in Javascript, for example, when a user clicks on an image, it gets automatically downloaded. For example I have an image tag <code>&lt;img src="filelocation" id="img"/&gt;</code> and want it to be downloaded on click. (I can't use <code>"download="myfile.png"</code>.</p>
  
  <p>Is there something like  </p>
  
  <pre><code>$('#img').on('click',function(e){
    img.download="myfile.png";
  });
  </code></pre>
  
  <p>All the answers online suggest adding the <code>download="..."</code> into my tag </p>
  
  <p>Thanks! </p>