title: How to change a file name and download it when a button is clicked using JavaScript
body: <p>I have one download button created in JavaScript that links to particular file.</p>
  
  <pre><code>var strDownloadButton = "&lt;br/&gt;&lt;INPUT type="button" value="Download" onclick="add()"/&gt;"
  window.location.href = "/images/image1.jpg";
  </code></pre>
  
  <p>I have to rename the file <code>image1</code> to <code>image2</code> before downloading, so I use:</p>
  
  <pre><code>&lt;a href="/images/image1.jpg" download="image2" &gt;Download&lt;/a&gt; 
  </code></pre>
  
  <p>The problem is that there are 2 download buttons created (HTML5 download attribute created 1 more). </p>
  
  <p>Is there any way to use the same button created by JavaScript, and refer into download attribute?</p>