[Solved] How can I make a point and let it disappear when making a new point


You can use ctx.clearRect(0, 0, c.width, c.height); to clear the content.

function showCoords(event) { 
  i++; 
  
  var x = event.clientX; 
  var y = event.clientY;
  var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
  ctx.clearRect(0, 0, c.width, c.height);
  console.log(x,y);
  var coords = "X coords: " + x + ", Y coords: " + y; 
  document.getElementById("demo").innerHTML = coords; 
  if(i%2==0) { 
    ctx.beginPath(); 
    ctx.arc(x-10,y-10,5,0,2*Math.PI);
    ctx.stroke(); 
  } else { 
    ctx.beginPath();
    ctx.arc(x-10,y-10,5,0,2*Math.PI); 
    ctx.fill(); 
    ctx.stroke();
  }
}
var i=0;
$(document).click(showCoords)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="demo"></div>
 <canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">

Working demo

0

solved How can I make a point and let it disappear when making a new point