var canvas = document.createElement("canvas"); var img = document.getElementById("img"); img.parentNode.replaceChild(canvas,img); img.element = canvas;