Here is some sample code that works: (Just change the image sources.)
Code:
<script type="text/javascript">
function change(str) {
document.getElementById("myTextarea").value = str;
}
function imgOn(el) {
img = el.firstChild;
while(String(img.tagName).toLowerCase()!=="img") img = img.nextSibling;
var src = img.src.replace(/(\.\w+)$/, "");
img.src = src.substring(0, src.length-1)+2+RegExp.$1;
}
function imgOff(el) {
img = el.firstChild;
while(String(img.tagName).toLowerCase()!=="img") img = img.nextSibling;
var src = img.src.replace(/(\.\w+)$/, "");
img.src = src.substring(0, src.length-1)+1+RegExp.$1;
}
</script>
<span id="element1">
<a href="#"
onmouseover="(function(el){change('John Hartmans\' Cinelli Supercorsa'); imgOn(el)})(this)",
onmouseout="(function(el){change(''); imgOff(el)})(this)">
<img border="0" alt="#" src="MbikeDir/the_cinelli1.png" name="cinelli" height="100" width="100"/>
</a>
</span>
<span id="element2">
<a href="#"
onmouseover="(function(el){change('Jon Foster\'s Crowbot'); imgOn(el)})(this)",
onmouseout="(function(el){change(''); imgOff(el)})(this)">
<img border="0" alt="#" src="foster/crowbot1.png" name="foster" height="100" width="100"/>
</a>
</span>
<span id="element3">
<a href="#"
onmouseover="(function(el){change('Keith Parkinson\'s North Patrol'); imgOn(el)})(this)",
onmouseout="(function(el){change(''); imgOff(el)})(this)">
<img border="0" alt="#" src="parkinson/northPatrol1.png" name="parkinson" height="100" width="100"/>
</a>
</span>
<textarea id="myTextarea"></textarea>
The imgOn() changes xxx/yyy1.zzz to xxx/yyy2.zzz, and the imgOff() changes xxx/yyy2.zzz to xxx/yyy1.zzz.
In other words, it gives it the same source file, except instead of making the new source something like test1.bmp, it makes it test2.bmp.
Oh, and there was a mistake in my containing function. Instead of
Code:
function(e){func1()....}
It should be
Code:
(function(el){func1()....}(this))
Bookmarks