How to assign onclick to a variable in a canvas? : <p>I'm trying to make the circle I've made in canvas have an onclick event. I tried the following with no success. If anyone can offer some pointers, that would be great.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div id="type"&gt;&lt;/div&gt;
&lt;canvas id="ctx2" width="500" height="500" style="border: solid 1px;"&gt;&lt;/canvas&gt;
&lt;script&gt;
var ctx = document.getElementById("ctx2").getContext("2d");
//var message = 'Hello John, this is your canvas.';
//ctx.fillStyle = 'red';
//ctx.font = '30px Arial';
//ctx.opacity = 0;
//ctx.fillText(message,50,50);

ctx.beginPath();
ctx.arc(100,75,50,0,2*Math.PI);
ctx.stroke();
ctx.onclick = displayDate(); // This is what I used (stack overflow)

function displayDate() {
    document.getElementById("type").innerHTML = Date();
}

document.getElementById("type").innerHTML = typeof ctx


&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
