I attempted to duplicate an image swap but the mouseout ends up being image 3 on each of the three swaps when I’d only like it to be on the last. Any help I can get on figuring out how I make the swaps distinct from one another so they are not calling the same image would be much appreciated, thanks!
//---imageswap1
if(document.images) {
cars1 = new Array();
cars1[1] = new Image();
cars1[1].src = "car4.png";
cars1[2] = new Image();
cars1[2].src = "car1.png";
}
function swapping_pics(picture_name, value_2) {
document.images[picture_name].src = cars1[value_2].src;
}
//---imageswap2
if(document.images) {
cars2 = new Array();
cars2[1] = new Image();
cars2[1].src = "car5.png";
cars2[2] = new Image();
cars2[2].src = "car2.png";
}
//---imageswap3
function swapping_pics(picture_name, value_2) {
document.images[picture_name].src = cars2[value_2].src;
}
if(document.images) {
cars3 = new Array();
cars3[1] = new Image();
cars3[1].src = "car6.png";
cars3[2] = new Image();
cars3[2].src = "car3.png";
}
function swapping_pics(picture_name, value_2) {
document.images[picture_name].src = cars3[value_2].src;
}
<div id="imageswap1" onMouseOver="swapping_pics('car1',1)" onMouseOut="swapping_pics('car1',2)" href="javascript:void">
<img name="car1" border=”0” src="car1.png" alt="car1">
</div>
<div id="imageswap2" onMouseOver="swapping_pics('car2',1)" onMouseOut="swapping_pics('car2',2)" href="javascript:void">
<img name="car2" border=”0” src="car2.png" alt="car2">
</div>
<div id="imageswap3" onMouseOver="swapping_pics('car3',1)" onMouseOut="swapping_pics('car3',2)" href="javascript:void">
<img name="car3" border=”0” src="car3.png" alt="car3">
</div>
You can’t have multiple functions with the same name:
swapping_pics, to solve your problem, you could add an id to each function, like:swapping_pics_01,swapping_pics_02,swapping_pics_03.But this, doens’t solve the mess that you have, instead of all that code, CSS can do that in a much better way …
HTML:
CSS:
Fiddle with the example: http://jsfiddle.net/qnw6j/