4

I want to create a canvas object in memory, and not require a HTML <canvas> tag. Is this possible?

With this code:

var canvas = new Canvas();
var ctx = canvas.getContext('2d');

I get this error message: Uncaught ReferenceError: Canvas is not defined

2 Answers 2

10

You should be able to create the element with JavaScript:

var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
Sign up to request clarification or add additional context in comments.

Comments

4

Use document.createElement("canvas") instead. There is no Canvas constructor for canvases, as you know it from Image for images or Option for options - those are the sole exceptions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.