Arjen van Heck Arjen van Heck - 2 years ago 168
HTML Question

HTML5 Dynamically create Canvas

Hi there i have a question about dynamically creating a canvas using javascript.

i create a canvas like this:

var canvas = document.createElement('canvas'); = "CursorLayer";
canvas.width = 1224;
canvas.height = 768; = 8; = "absolute"; = "1px solid";

but when I try to locate it, I get a

cursorLayer = document.getElementById("CursorLayer");

Am I doing it wrong? Is there a better way to create a canvas using JavaScript?

Answer Source

The problem is that you do not insert your canvas element in the document body.

Just do the following:



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download