2

I have a button to clear the drawings of my canvas element as follows:

<button id="button_clear" onclick="clear()" > Clear ! </button>

<canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;">

Clear function is like that :

function clear(){

  var c = document.getElementById("myCanvas");
  var ctx = c.getContext("2d");
  ctx.clearRect(0, 0, c.width, c.height);
  ctx.beginPath();

}

However when I click on the clear button, my function does not do anything at all.

Scott Marcus
  • 64,069
  • 6
  • 49
  • 71
ayt_cem
  • 105
  • 1
  • 9

1 Answers1

2

Try to avoid using function names something like click(), clear(), ... Change your function name and check if it works. Check this answer for more detail information https://stackoverflow.com/a/5454341/5344661

Community
  • 1
  • 1
mudin
  • 2,672
  • 2
  • 17
  • 45