I am new to html5. I have written a small code that add a rectangle on canvas. When I double click on canvas, some how it is not working can any one guide me where am I doing wrong?
<script>
function init() {
var canvas2 = document.getElementById("canvas2");
canvas2.ondblclick = doubleclickhandler;
}
function doubleclickhandler (){
var canv = document.getElementById("canvas2");
var ctx = canv.getContext("2d");
ctx.fillStyle = "rbga(0,200,0,1)" ;
ctx.fillRect = (36,10,22,22);
}
</script>
<style>
#div2
{
float:left;
width:100px;
height:150px;
margin:10px;
border:1px solid #aaaaaa;
}
</style>
<body onLoad="init()">
<div id= "div2">
<canvas id="canvas2" width="100" height="150" ></canvas>
</div>
</body>
ctx.fillRect = (36,10,22,22)is an assignment, whilectx.fillRectis usually a method, not an attribute. You need to call it like a function: