how to change a background image in canvas by button click

this code can change a background image in canvas by button click
#canvas{
	position: absolute;
    left: 0px;
    top: 0px;
    background-image:url('../images/t1.png');
    background-repeat: no-repeat;
    width: 120px;
    height: 120px;
}


<div id="myCanvas">
<canvas id="canvas" width="120" height="120"></canvas>
</div>		
<button type="button" onClick="changeBackground()">change	</button>



function changeBackground(){
	document.getElementById("canvas").style.background = "url(images/t2.png)";
}

Responses

0 Replies