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
https://forums.phpfreaks.com/topic/24695-changing-onmousedown-events/
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

Archived

This topic is now archived and is closed to further replies.

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