I have the following HTML code snippets
<body onload="main()" >
...
<canvas id="myId" class="myClass"></canvas>
...
</body>
It works as expected. I can display the output correctly.
I then remove
<canvas id="myId" class="myClass"></canvas>
Because I want to create it programmatically with the following JavaScript code snippet
var canvas = document.createElement("canvas");
canvas.className = "myClass";
canvas.id = "myId";
Unfortunately, it didn't work. I cannot display anything with this.
I am wondering if I miss something. Any help is appreciated. Thanks in advance for your help.