PDA

View Full Version : Image Swap on text link



bkirish
08 Apr 2010, 07:35 PM
I am building a website and have an issue that is driving me NUTS!

I have set an image swap on the page when the viewer hovers over a link using the following code:

<a href="" onClick="document.main.src='image.png';">image swap text
</a>

It is functioning to swap the image , but ONLY on the moment of the click. Afterward, the original image comes back onscreen. I would like to make it so that the new image stays unless a different image swap link is clicked. I know you can succeed in doing this using another div and adding an image swap behavior, but I would prefer to have the text link work as desired. Anyone have a solution?

BIOSTALL
09 Apr 2010, 03:42 PM
Your link has a blank 'href' attribute which means when the link is clicked the page is just refreshing.

Either a) set the href to something like 'javascript://' or b) add 'return false;' to the end of your onclick.

Hope that helps,

BIOSTALL