I have the following HTML canvas':
<div id="graphs">
<canvas id="graph1" ></canvas>
<canvas id="graph2" ></canvas>
<canvas id="graph3" ></canvas>
</div>
On a click of a button, I want to remove canvas #graph1 and replace it will a new (chartjs) canvas. So I tried the following code:
dayButton.addEventListener("click", function(){
var canvas = $("#graph1").get(0);
canvas.parentNode.removeChild(canvas);
var parent = $("#graphs").get(0);
var new_canvas = document.createElement("canvas");
var new_ctx =new_canvas.getContext("2d");
myChart = new Chart(new_ctx).Line(somedata);
parent.appendChild(new_canvas);
}
This gets the Canvas to properly remove, but I am having a hard time trying to append the new child (with the correct context and in the same spot as the removed child) back into the DOM.