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

  • Home
  • SEARCH
  • 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 8429441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:20:24+00:00 2026-06-10T05:20:24+00:00

I am using javascript to draw to a canvas element inside a div, contained

  • 0

I am using javascript to draw to a canvas element inside a div, contained within a wrapper.
The canvas and its div are generated dynamically by adding to the wrapper’s innerHTML.
The goal is to allow an infinite number of canvases to be generated

<div id="wrapper">
     <div id="container"><canvas id="previous"></canvas></div>
     <!-- infinite # of container divs & canvases -->
</div>

However, when I add a new div and canvas to the wrapper’s innerHTML anything drawn to the previous canvas is lost.

Where if I add a new canvas elsewhere on the page, to a div outside of the container, or a child of the container:

<div id="wrapper">
     <div id="container"><canvas id="previous"></canvas></div>
</div>
<div id="wrapper2">
     <!-- newly inserted canvas: -->
     <div id="container"><canvas></canvas></div>
</div>

or:

<div id="wrapper">
     <div id="container"><canvas id="previous"></canvas></div>
     <div id="wrapperChild">
          <!-- newly inserted canvas: -->
          <div id="container"><canvas></canvas></div>
     </div>
</div>

Then the previous canvas is preserved.

From what I can tell changing the innerHTML of the wrapper or it’s parents results in clearing the canvas. Any advice on how I can avoid clearing the canvas? Can I preserve what’s been drawn to the canvas elsewhere and restore it?

  • 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-06-10T05:20:26+00:00Added an answer on June 10, 2026 at 5:20 am

    Regardless of your javascript approach (jQuery, something else, or nothing), you can do this by not using innerHTML. Basically, when you append to the innerHTML property, you’re saying “take the value of innerHTML, add it to this new value (the canvas element, perhaps), then set innerHTML to all of that. In other words, you aren’t really appending “in place”. You’re basically adding a fresh version of everything you have, and since the canvas isn’t drawing its contents with child elements, they aren’t going to be brought over with this method.

    Instead of using innerHTML, you should be working with the DOM, appending children to the parent as nodes instead of strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a JavaScript project (using jquery), inside it i draw a canvas by
We're using Javascript to draw polylines on a <canvas> element, based on some spatial
I've seen on some websites using the <canvas> tag with javascript to draw text
You can draw arcs and you can draw images on a canvas using javascript,
I am trying to draw some shapes on the HTML5 canvas using Javascript. When
HTML5 canvas provides lots of flexibility to draw images using javascript. We need to
I use canvas in my application using JavaScript. On that canvas I draw one
I'm hosting a little site using a JavaScript to draw a simple graph. It
Is there a way to draw an arc using points in JavaScript?? I need
using Javascript, it is easy to programatically select the text inside a textarea or

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.