Jump to content

Image swap/restore.....


unplugged_web
 Share

Recommended Posts

I have a simple image that is changed to another image when somebody clicks on it. I want the original image to be restored when they click again. I've used
 <img src=".images/tc.gif" id="Image1" onClick="MM_swapImage('Image1','','/images/tc_active.gif',1)" onClick="MM_swapImgRestore()">

You can't put two onclick attributes! Unless you have one of those MM_ functions that handles the toggling itself, you'll have to create a little function that checks what the image currently is, and sets it to the other image. You would then put your new function as the onclick attribute value.
Link to comment
Share on other sites

E.g.

<script>	function swapImage(target, old, new) {		if (target.src == old) {			target.src = new;		} else {			target.src = old;		}</script><img src="old_image.gif" onclick="swapImage(this, 'old_image.gif', 'new_image.gif')" />

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...