I am trying to use Javascript to replace an image while I can get it from A to B, but haven't returned.
Here is what I use to create one swap:
<img src="pic1.png" name="pic" onclick="window.document.pic.src='pic2.png';"/>
This reduces image 1 to image 2, which is quite simple. But I want to return to image 1 by clicking on the new image 2. I tried to use this:
<img src="pic1.png" name="pic" onclick="
if (window.document.pic.src='pic1.png'){
window.document.pic.src='pic2.png';
}
else if (window.document.pic.src='pic2.png'){
window.document.pic.src='pic1.png';
}"/>
In this case, it does not work. It will switch to pic2, but will not switch to pic1. Does this have anything to do with onclick? My if statements? Thanks
source
share