2๐
โ
My suggestion is create canvas node programatically as below and attach.
var canvas = document.createElement("canvas");
canvas.id = "my-id";
specContainerNode.appendChild(canvas);
// ----- more code ------
setTimeout(function() {
/* TIP: This timeout will be helpful to execute logic after a repaint.
Thus, this block will execute only after nodes were attached */
// ----- more code -----
}, 0);
See this Q&A for more info.
Source:stackexchange.com