Getting a context

The canvas API is accessed via a canvas context object. You get the context by calling the getContext() method of the <canvas> element, passing in a string parameter that defines the type of the context you want:

var context = $("canvas")[0].getContext("2d");

The only valid context type parameter you can pass into getContext() at this time is "2d". This begs the question, "Is there a 3D context?" The answer is no, there is not. But we can always hope for one in the future.

Get HTML5 Web Application Development By Example Beginner's guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.