Hi,
Please refer the below example.
<input type="button" value="Draw" onclick="Draw()" />
<input type="button" value="Clear" onclick="Clear()" />
<script>
function Draw() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.font = "14pt Arial";
context.fillText('MUDASSAR KHAN', 10, 30);
};
function Clear() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
};
</script>
<canvas id="myCanvas" width="300" height="100"></canvas>
Demo