I am working in JavaScript and I am trying to click on an object and make something simple happen, like an alert for example.
So I've declared the object as such:
var panel = new Image();
panel.src = IMAGES_PATH + "panel.png";
Then I've drawn it to the screen.
ctx.drawImage(panel, 475, 140);
The problem I am facing now is that I want to click on it and I want a function to fire.
Attempt #1
panel.onclick = function () {
alert("You clicked!");
}
Attempt #2
panel.addEventListener('click', function ()
{
alert('blah');
}, false);
I know the click events are working in Google Chrome because I can do:
window.addEventListener("click", click, false);
Any ideas to why I can't do an onclick for the Image class?