Implement a functionality in which lines are drawn while the mouse button is held down and simultaneously display x & y coordinates on top of the mouse pointer during mouse movement using canvas and JavaScript.
The issue arises when attempting to draw lines while the mouse button is held down due to the use of ctxTemp.clearRect(0,0,canvasTemp.width,canvas.height), which removes the continuously updating x & y coordinates displayed on top of the mouse pointer during mouse movement.
If ctxTemp.clearRect(0,0,canvasTemp.width,canvas.height) is not used, then the x & y coordinates will continue to be drawn on top of the mouse pointer during mouse movement without any interruption.
Your assistance in resolving this dilemma would be greatly appreciated. Thank you in advance.