Javascript OnClick

Mondeo

Well-known member
Joined
Nov 10, 2006
Messages
128
Location
Sunny Lancashire
Hi,

Im trying to access the onClick of an image to run some javascript when the image is clicked.

document.getElementByID(imgMain).onClick = window.close

But it throws an error.

Microsoft JScript runtime error: Object doesnt support this property or method

Can this be done, if so whats the correct syntax?

Many Thanks
 
onclick

Two things.
Firstly, case is important - onclick must be lowercase.
Secondly, the desired action needs to be a function call:

Code:
document.getElementById(imgMain).onclick = function() {window.close();}

Good luck :)
 
Back
Top