Jump to content
rovf

getContext('2d') canvas question

Recommended Posts

Sorry, this is really a beginner's question:I stumbled over the following piece of JavaScript code:var ctx=element.getElementsByTagName('canvas')[0].getContext('2d')...var w=ctx.canvas.widthI understand what the code is doing. However, I was surprised to find, that we can extract the canvas out of the context (i.e. ctx.canvas), because when looking at http://www.w3schools.com/tags/ref_canvas.aspI find the following:"This reference will cover the properties and methods of the getContext("2d") object"but looking below, I do not find an attribute "canvas" listed. Did I misunderstand the documentation, i.e. are there maybe even more attributes or methods available for the context object, than are listed on ref_canvas.asp? Or why has the "canvas" attribute been left out?

Share this post


Link to post
Share on other sites

The canvas property is a back-reference to the canvas from which the context was created. Check the MDN reference for the canvas:

 

https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement

 

and the 2D context:

 

https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...