View Full Version : Multiple onclicks for 1 element?

03-01-2011, 07:17 PM
Not sure if I worded the subject correctly but I would like to have the onclick for a particular element swap out an image and then a second click on the same element brings back the original image and a third click swaps to the second image again and a 4th click bring back the original, and so on.

In other words: swap back and forth between 2 images each time you click on the same element.

I have this code to switch to the second image:


now I want to be able to click again and go back to the orig image.

03-02-2011, 09:27 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<script type="text/javascript">

function Toggle(obj,url){
var swap=window[obj.id+'swap'];
if (!swap){



<img id="tst" src="http://www.vicsjavascripts.org.uk/StdImages/Egypt5.jpg" alt="Img" onmouseup="Toggle(this,'http://www.vicsjavascripts.org.uk/StdImages/Egypt6.jpg');"/>