without seeing your html, this question is a bit unclear, it seems you would like to draw something on the canvas and use jquery to add click events for the circle, this is not possible.
you can use jquery to get the click event on the canvas and from the cursor position, which you can calculate if the user clicked on the circle or not, but jquery does not help you here, you need to do the math yourself.
jquery only works for dom elements.
BigCircle = function(ctx,x, y, color, circleSize) { ctx.beginPath(); ctx.arc(x, y, circleSize, 0, Math.PI * 2, true); ctx.fillStyle=color ctx.fill(); ctx.closePath(); this.clicked=function(){ ctx.fillStyle='#ff0000' ctx.fill(); } }; function init() { var canvas = document.getElementsByTagName("canvas")[0]; var ctx = canvas.getContext('2d'); var bigGreen = new BigCircle(ctx,50, 50, '#5eb62b', 50); $('#canvas').click(function(e){ var x = e.clientX , y = e.clientY if(Math.pow(x-50,2)+Math.pow(y-50,2) < Math.pow(50,2)) bigGreen.clicked() }) } $(document).ready(function() { init(); });
jsfiddle here http://jsfiddle.net/yXVrk/1/
supernova
source share