How to remove dashed line from HTML context
I will try to explain as simple as I can:
You can pass empty array. It also makes line solid.
ctx.setLineDash([])
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
ctx.setLineDash([5, 3]);
ctx.strokeRect(20, 20, 150, 100);
button.onclick = () => {
ctx.clearRect(15, 15, 200, 200);
ctx.setLineDash([]);
ctx.strokeRect(20, 20, 150, 100);
}
<!DOCTYPE html>
<html>
<body>
<button id='button'>Unset Dashed Line</button><br>
<canvas id="myCanvas" width="300" height="150" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
</body>
</html>
Wrap your code inside context.save
/ context.restore
ctx.save();
ctx.setLineDash([5]);
// draw dashed stuff
ctx.restore();
// now the default solid line is restored