title: Clear canvas button
body: <p>I am trying to create a button to clear a canvas, but with no success.</p>
  
  <p>My codes for this</p>
  
  <p>JS</p>
  
  <pre><code>function clearcanvas1(){
  ctx.clearRect(0, 0, canvas.width, canvas.height); 
  var w = canvas.width; canvas.width = 1; canvas.width = w; 
  }
  </code></pre>
  
  <p>HTML</p>
  
  <pre><code>&lt;button onmouseover="clearcanvas1()"&gt;clear&lt;/button&gt;
  </code></pre>
  
  <p>I have tried other options such as</p>
  
  <pre><code>canvas.width = canvas.width;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
  </code></pre>
  
  <p>At the moment I have substituted the clear button for a location.reload function, but it upsets a secondary canvas on the same page which I want to operate independently.
  How can i achieve this?</p>