title: Trigger a file download on click of button Javascript with contents from DOM
body: <p>I want to download a file which is created from DOM element. So a user clicks a button on web page and it invokes a javascript method which may grab the contents of DOM element and prompt user for download. </p>
  
  <p>I am able to grab contents of the DOM element inside a Javascript Var. But not sure how to proceed further. </p>
  
  <p>For grabbing the DOM element i am using:</p>
  
  <pre><code>var elem = document.getElementById("userDownload");
  </code></pre>