I want to make an image swap.
I have a link, on this links onmouseover and onmouseout i want to change a image. How can i do this???
/Smirre
Printable View
I want to make an image swap.
I have a link, on this links onmouseover and onmouseout i want to change a image. How can i do this???
/Smirre
onmouseover="pic('button','pic-off.gif')"
onmouseout="pic('button','pic-on.gif')"
I think thats how its done :)
I have used this code to change the image:
document.images['imagename'].src = image1.src;
the image1 is created like this:
image1 = new Image;
image1.src = "grahpics/imagename.gif";
is this syntax correct or???
coudnt the documnet.images be set to the image1 object instead of the src of both objects??? or???
/Smirre
Sorry thats gone over my head a bit .. What are you trying to do it in? JavaScript, XML or what?
javascript...
You dont really have to use document.images, you can still use document.all or getElementById. Try this (edited from the code I posted for you this morning)...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function changeImage(objectID,imageName){
findDom(objectID).src = imageName;
}
function findDom(objectID){
if (document.all){
return document.all(objectID);
} else if (document.getElementById){
return document.getElementById(objectID);
}
}
//-->
</script>
</head>
<body>
<img id="img1" src="image1.jpg" onmouseover="changeImage('img1','image1-2.jpg')" onmouseout="changeImage('img1','image1.jpg')">
</body>
</html>
Or if you are using Dreamweaver you can do it in the Rollover Image section..