CanvasRenderingContext2D.canvas

The CanvasRenderingContext2D.canvas property is a read-only reference to the HTMLCanvasElement object that is associated with the context. It might be null if there is no association with an <canvas> element.

Syntax

JavaScript
<var>ctx</var>.canvas;

Examples

Given this <canvas> element:

HTML
<canvas id="canvas"></canvas>

You can get a reference to the canvas element within the CanvasRenderingContext2D by using the canvas property:

JavaScript
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.canvas // HTMLCanvasElement

Specifications

Specification Status Comment
WHATWG HTML Living Standard
The definition of 'CanvasRenderingContext2D.canvas' in that specification.
Living Standard  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

License

© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/canvasrenderingcontext2d/canvas

API Canvas CanvasRenderingContext2D Property Reference Référence