title: Take screenshot of element (jpg,png) and then download it. Javascript
body: <p>I want to make a JS function which can take the screenshot from element and then download it.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
      &lt;h1&gt;Sample text&lt;/h1&gt;
      &lt;h2&gt;Sample text&lt;/h2&gt;
      &lt;table width="1080px" height="1920px" border="1" style="border-collapse:collapse"&gt;
          &lt;tbody&gt;&lt;tr&gt;
              &lt;td colspan="2"&gt;
                  &lt;img src="https://inspectiondoc.com/wp-content/uploads/2014/08/sample-icon.png" width="600px"&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  Sample text
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr style="background:#b6ff00"&gt;
              &lt;td&gt;
                  Sample text
              &lt;/td&gt;
              &lt;td&gt;
                  Sample text
              &lt;/td&gt;
              &lt;td&gt;
                  Sample text
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;&lt;/table&gt;
      &lt;h1&gt;
          sample text
      &lt;/h1&gt;
      &lt;h2&gt;Sample text&lt;/h2&gt;
      &lt;br&gt;&lt;br&gt;
      &lt;input type="button" value="Capture" onclick="capture()"&gt;
  
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>After clicking capture button I want this td colspan=&quot;2&quot; element to be screenshoted and downloaded on jpg or png format.</p>