title: How to trigger a file download when clicking an HTML button or JavaScript
body: <p>This is crazy but I don't know how to do this, and because of how common the words are, it's hard to find what I need on search engines. I'm thinking this should be an easy one to answer.</p>
  
  <p>I want a simple file download, that would do the same as this:</p>
  
  <pre><code>&lt;a href="file.doc"&gt;Download!&lt;/a&gt;
  </code></pre>
  
  <p>But I want to use an HTML button, e.g. either of these:</p>
  
  <pre><code>&lt;input type="button" value="Download!"&gt;
  &lt;button&gt;Download!&lt;/button&gt;
  </code></pre>
  
  <p>Likewise, is it possible to trigger a simple download via JavaScript?</p>
  
  <pre><code>$("#fileRequest").click(function(){ /* code to download? */ });
  </code></pre>
  
  <p>I'm definitely <em>not</em> looking for a way to create an anchor that looks like a button, use any back-end scripts, or mess with server headers or mime types.</p>