Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:47:47+00:00 2026-05-16T11:47:47+00:00

In one part of my code, I call getContext(‘2d’) on a canvas element to

  • 0

In one part of my code, I call getContext('2d') on a canvas element to produce a CanvasRenderingContext2D object. That object goes on to get passed around a fair bit from function to function, and at a later point in the code it’d be handy to be able to get a reference to the original canvas dom element that produced a given context. I can’t find anything in the spec that provides for this, but it seems like the sort of thing that ought to be possible. Ideas?

I can think of plenty of workarounds (pass the canvas element along with its context, etc.) but my code’s complicated enough already and I’d rather do it directly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:47:47+00:00Added an answer on May 16, 2026 at 11:47 am

    So you’ve got your context:

    var ctx = myCanvas.getContext('2d'); // the canvas' 2d context
    

    later on you can always do:

    ctx.canvas // the context's canvas, which in this case is the same as myCanvas
    

    From the Canvas spec:

    interface CanvasRenderingContext2D {
    
      // back-reference to the canvas
      readonly attribute HTMLCanvasElement canvas;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title really, I'm in one part of my code and I would
I'm working with some example java code for making md5 hashes. One part converts
Should libraries that the application relies on be stored in source control? One part
I have an OpenGL ES game that I am hacking together. One part of
I have an application that I have to run as Administrator. One small part
Our project has one folder that is not part of the solution. How can
If one has a project that has tests that are executed as part of
I have a code behind page that has several method; one of them is
I have a site in rails and want to have site-wide settings. One part
So let's say I have two different functions. One is a part of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.