Log in

View Full Version : Image change on click, changeback on click



Racuda
07-23-2007, 03:56 PM
Probably a simple script, if possible... ;) I have a headache and can't think :o , but tbh I'm not very good at creating scripts, just editing and using them. :D

I need a script that changes an image for example image1.gif when it's clicked to another image for example image2.gif, and when clicked again, back to image1.gif, and clicked again, image2.gif, click again image1.gif... i think you get my point. :P

If anyone can offer me any help, I would be grateful, thanks. :D

Twey
07-23-2007, 04:39 PM
<script type="text/javascript">
onload = function() {
for(var i = 0, es = document.images, n = es.length, e = es[0]; i < n; e = es[++i]) {
var m = e.className.match(/swap\((\w+), ([\w\/\.:&#37;]+)\)/);
if(m)
e['on' + m[1]] = (function(n) {
return function() {
var oldsrc = this.src;
this.src = n;
n = oldsrc;
};
})(m[2]);
}
e = es = null;
};
</script>
</head>
<body>
<p>
<img alt="Something" src="image1.gif" class="swap(click, image2.gif)">You can use as many images as you like in that format (theoretically, I haven't tested it).

Racuda
07-23-2007, 05:52 PM
Thank You Very Much! Consider yourself a legend! :D :D :D :D