1

Im trying to export a canvas to a png but Im not sure if when calling for the canvas as a class i get the right return:

var canvas = document.getElementsByClassName('filemanager');
canvas.setAttribute('crossOrigin', 'anonymous');
function download() {var dt = canvas.toDataURL();
this.href = dt; //this may not work in the future..}document.getElementById('download').addEventListener('click', download, false);

In the html i have: <a id="download" download="YourFileName.jpg">Download as image</a> I read somewhere about how when calling functions you do not get back the same desired return, is the document.getElementById()different from document.getElementsByClassName() in terms of what you receive back?

  • 1
    `getElementsByClassName` returns an array, so `var canvas = document.getElementsByClassName('filemanager')[0] ;` – Arun P Johny Dec 07 '16 at 02:00
  • Another option would be `document.querySelector('.filemanager')`. See [Document#querySelector](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector). – gyre Dec 07 '16 at 02:07

0 Answers0