Monday, 19 August 2013

switch multiple images on click

switch multiple images on click

I have the code to switch an image back and forth and it works fine.
However, I was wondering if there was a way to rewrite the script so I can
use it in multiple places. This is my code currently:
function swaparrows(obj) {
var x=document.images
if (x[0].src.match('images/editloadout.png')) {
x[0].src="images/editloadoutopen.png";
}
else if (x[0].src.match('editloadoutopen.png')) {
x[0].src="images/editloadout.png";
}
}
<img src="images/editloadout.png" onclick="swaparrows()" />
which works for this one specific instance only. I would like it to work
in multiple places with different pictures entirely.

No comments:

Post a Comment