Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm 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 doesn't support this property or method

 

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

 

Many Thanks

Posted

onclick

 

Two things.

Firstly, case is important - onclick must be lowercase.

Secondly, the desired action needs to be a function call:

 

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

 

Good luck :)

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...