title: Javascript Clear Canvas
body: <p>I have a button to clear the drawings of my canvas element as follows: </p>
  
  <pre><code>&lt;button id="button_clear" onclick="clear()" &gt; Clear ! &lt;/button&gt;
  
  &lt;canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;"&gt;
  </code></pre>
  
  <p></p>
  
  <p>Clear function is like that :</p>
  
  <pre><code>function clear(){
  
    var c = document.getElementById("myCanvas");
    var ctx = c.getContext("2d");
    ctx.clearRect(0, 0, c.width, c.height);
    ctx.beginPath();
  
  }
  </code></pre>
  
  <p>However when I click on the clear button, my function does not do anything at all.</p>