O'Reilly logo

HTML5 Web Application Development By Example Beginner's guide by J.M. Gustafson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required