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?
I had a problem because my canvas was inside of a container without ID so I used this jquery code below
$('.cropArea canvas').width()
now starting 2015 all (major?) browsers seem to alow c.width
and c.height
to get the canvas internal size, but:
the question as the answers are missleading, because the a canvas has in principle 2 different/independent sizes.
The "html" lets say CSS width/height and its own (attribute-) width/height
look at this short example of different sizing, where I put a 200/200 canvas into a 300/100 html-element
With most examples (all I saw) there is no css-size set, so theese get implizit the width and height of the (drawing-) canvas size. But that is not a must, and can produce funy results, if you take the wrong size - ie. css widht/height for inner positioning.