Jump to content

Changing onmousedown events?


zq29

Recommended Posts

Not sure if my topic title was confusing enough, but I have an image that runs a function when clicked, in the function that is then run, I want to change what function is run when a different image is clicked. An example might make this a little clearer:

[code]
function swapImage(target) {
    document.getElementById("square").src = "circle.gif";
    document.getElementById("square").onmousedown = "iAm('circle')";
}

function iAm(desc) {
    alert("I am a "+desc);
}

<img src="square.gif" alt="a square" id="square" onmousedown="iAm('square');"/>
[/code]
Now, the bit that doesn't work is the [i]document.getElementById("square").onmousedown = "iAm('circle')";[/i] - Is this possible, if so, how is it done?

Many thanks :)
Link to comment
Share on other sites

have you tried something like this.

[code]
functon swapImage(target, image) {
  document.getElementById('square').src = 'circle.gif';
  if (document.images) {
      document[image].onmouseover = "yourfunction('target', 'image');";
  }
}
[/code]

I have not tried this but.. If it were a link you could do this document.links[link].yourevent = whatever.

If this works please let me know. It will be good for future information.

Good Luck,
Tom
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.