SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    brazil
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    image swap not working in IE and Opera

    i dont know why this piece of code is not swapping my images in IE6 and Opera; they are working fine in NS6.2 and Mozilla 1.1

    Code:
    <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>
    Please help!

  2. #2
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE returns the full path of the image, so your if (imageSrc == up) does not work. Change it to something like this:

    Code:
    if (imageSrc.indexOf(up) >= 0)

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    brazil
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks lpok! worked perfectly


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •