i need a script that swaps multiple images, in which when i call the function, i type swap(‘../myimg.gif’) to specify which image i want it to change into. also, i need it to change back to the original when a different image is clicked…
@gil_davisAug 04.2003 — #If you only have one active "swap", jut keep track of that one and then "unswap" it when the next one is "swapped". Something like this: <i> </i>var activeImg = null; // first time it will be empty ... function unSwap() { document.images[activeImg.name].src = activeImg.src; }
function swap(nm, src) { if (activeImg) unSwap(); activeImg = new Image(); activeImg.name = nm; // remember the old state activeImg.src = document.images[src]; document.images[nm].src = src; // do the swap }