PDA

View Full Version : image swap not working in IE and Opera


tom-mt
09-21-2002, 07:46 PM
hi all,

i dont know why this DOM-javascript piece of code is not working in IE6 and Opera6; it's working fine in NS6.2 and Moz1.1; can someone help?


<html>
<head>
<title> manipulating with the DOM </title>
<style type="text/css">

body {
font-family: verdana;
font-size: 12px;
background-color: #ccc
}

#logo {
border: 1px solid #000
}

</style>

<script language="javascript">

function imageSwap()
{
var up = "img1.jpg";
var over = "img2.jpg";
var imageObj = document.getElementById("logo");
var imageSrc = imageObj.getAttribute("src");
if (imageSrc == up)
{
imageObj.setAttribute("src", over );
}
else
{
imageObj.setAttribute("src", up );
}
}
</script>

</head>
<body>

<a href="" onmouseover="imageSwap()"
onmouseout="imageSwap()">
<img id="logo" src="img1.jpg" />
</a>
</body>
</html>

Vladdy
09-21-2002, 09:27 PM
Opera does not really support DOM.
I noticed IE does not like the setAttribute method - try using
imageObj.src=over;

umm
09-22-2002, 01:12 AM
here's a table listing the DOM support for various version 5 browsers. Might be helpful.

http://www.xs4all.nl/~ppk/js/version5.html

A1ien51
09-22-2002, 01:56 AM
try just doing this

<img src="main.gif" width="100" height="100" onmouseover="this.src='blah.gif'" onmouseout="this.src='main.gif'">