HTML DOM getContext() Method

Definition and Usage

The getContext() method returns an environment for drawing on the canvas.

Syntax

Canvas.getContext(contextID)

Parameter

Parameter contextID Specifies the type you want to draw on the canvas. The only valid value currently is "2d", which specifies 2D drawing and causes this method to return an environment object that exports a 2D drawing API.

Tip:In the future, if the <canvas> tag is extended to support 3D drawing, the getContext() method may allow passing a "3d" string parameter.

Return Value

A CanvasRenderingContext2D object, which can be used to draw into a Canvas element.

Description

Returns an environment type used for drawing. Its original intention is to provide different environments for different drawing types (2D, 3D). Currently, only "2d" is supported, which returns a CanvasRenderingContext2D object, which implements most of the methods used by a canvas.