title: How to access variable outside js function
body: <p>Probably trivial, but I have no idea how to do it... I want to access img outside of createThumbnail. How can I do that?</p>
  <h1>Function</h1>
  <pre><code>function createThumbnail(){
      canvas.deactivateAll().renderAll(); 
      html2canvas($('#chartdiv'), {
          onrendered: function(canvas) {
              var img = canvas.toDataURL(&quot;image/png&quot;),
                  elem = document.getElementById(&quot;thumbnail_img&quot;);
                  elem.src = img;
          }
      });
  }
  </code></pre>