Events attached to object inside canvas
问题 I have simply canvas code which draw rect on the canvas var x=document.getElementById("canvas"); var ctx=x.getContext("2d"); ctx.rect(20,20,150,100); ctx.stroke(); is it possible to add eventListener on said rect? For example, if I click on rect, it will turn red. 回答1: Regions Depending on how well you want to support various and older browsers, there is addHitRegion() that you can use by enabling it through flags in Firefox and Chrome (at the moment of this being written): Firefox: about