not sure if this is possible keeping the code simple, but im trying to make it so that i have an image, when you clicked it, it goes to a new image. then when you click that image, it goes back to the original image.
my code is:
function save_data()
{
if ( document.images.save.src == "saved.png") document.images.save.src="save.png";
if (document.images.save.src == "save.png") document.images.save.src="saved.png";
}
<img id="save" onclick="save_data()" src="save.png">
It can be simplified.
Using
You can do
If this doesn’t work, it may have to do with the fact that
saved.pngis not in the path the html is in. So try it with a full URL:A note: it may be better to assign the click handler unobtrusively (see also this SO question)