views:

42

answers:

2

hello, how can i get the width and height of the canvas element in javascript?

also, what is the "context" of the canvas i keep reading about?

thanks!

+2  A: 

It might be worth looking at a tutorial: Firefox Canvas Tutorial

The width and height are properties of the canvas element and the content is an object you get from the canvas to allow you to draw into it.

andrewmu
+2  A: 

The context object allows you to manipulate the canvas; you can draw rectangles for example and much more.

If you want to get the width and height, you can just use the standard HTML attributes width and height:

var canvas = document.getElementById( 'yourCanvasID' );
var ctx = canvas.getContext( '2d' );

alert( canvas.width );
alert( canvas.height ); 
Harmen