Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to avoid clearing canvas element on changing it's container's innerHtml
    primarykey
    data
    text
    <p>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</p> <pre><code>&lt;div id="wrapper"&gt; &lt;div id="container"&gt;&lt;canvas id="previous"&gt;&lt;/canvas&gt;&lt;/div&gt; &lt;!-- infinite # of container divs &amp; canvases --&gt; &lt;/div&gt; </code></pre> <p>However, when I add a new div and canvas to the wrapper's innerHTML anything drawn to the previous canvas is lost.</p> <p>Where if I add a new canvas elsewhere on the page, to a div outside of the container, or a child of the container: </p> <pre><code>&lt;div id="wrapper"&gt; &lt;div id="container"&gt;&lt;canvas id="previous"&gt;&lt;/canvas&gt;&lt;/div&gt; &lt;/div&gt; &lt;div id="wrapper2"&gt; &lt;!-- newly inserted canvas: --&gt; &lt;div id="container"&gt;&lt;canvas&gt;&lt;/canvas&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>or: </p> <pre><code>&lt;div id="wrapper"&gt; &lt;div id="container"&gt;&lt;canvas id="previous"&gt;&lt;/canvas&gt;&lt;/div&gt; &lt;div id="wrapperChild"&gt; &lt;!-- newly inserted canvas: --&gt; &lt;div id="container"&gt;&lt;canvas&gt;&lt;/canvas&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Then the previous canvas is preserved.</p> <p>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? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload