changing an image

liunx

Guest
i have an image in my page :<br />
<img src=http://www.webdeveloper.com/forum/archive/index.php/"pic_off"></img><br />
and i want by code to swap this image to another image<br />
how do i do that?<!--content-->I assume you mean when the mouse goes over it.<br />
You can either do this in JavaScript or CSS. Which are you more familiar with?<!--content-->i have found how to do it<br />
but instead of telling me every time to use css (what is not good for what i need) write down some code to show how to swap image using code<!--content-->Chill!<br />
<br />
Swapping images in CSS isn't good anyway - it isn't very compatible at all.<br />
<br />
Instead you should probably use JavaScript. As per your request, here's some code:<br />
<br />
<br />
<br />
<a onmouseover="javascript:document.getElementById('image1').src='http://www.webdeveloper.com/forum/archive/index.php/newimage.gif'" onmouseout="javascript:document.getElementById('image1').src='http://www.webdeveloper.com/forum/archive/index.php/oldimage.gif'"><img alt="cyclops_angry name="image1" id="image1" (1K)" src=http://www.webdeveloper.com/forum/archive/index.php/"oldimage.gif" height="45" width="45" /></a><!--content-->:)<!--content-->Originally posted by cijori <br />
Swapping images in CSS isn't good anyway - it isn't very compatible at all. Considering that about 13% of users are not using JavaScript (<!-- m --><a class="postlink" href="http://www.thecounter.com/stats/2003/May/javas.php">http://www.thecounter.com/stats/2003/May/javas.php</a><!-- m -->) and that a statistically insignificant number of users use browsers that do not understand CSS (<!-- m --><a class="postlink" href="http://www.thecounter.com/stats/2003/May/browser.php">http://www.thecounter.com/stats/2003/May/browser.php</a><!-- m -->) I'd say that you are wrong. And I'd point out that your JavaScript is wrong to, it's just that browsers are recovering well from the error.<!--content-->I thought IE didn't like using CSS2 to swap images? And could you tell me what is wrong with the JavaScript, so I don't make the same mistake again?<!--content-->You are employing the "javascript:" pseudo protocol that is often used with the "href" attribute of an A element. The value of an event handler ought to be pure script and before using one, you ought to have specified the language using something like the following in the ddocument head.<br />
<br />
<meta name="Content-Script-Type" content="text/javascript"><!--content-->Thankyou! I will aspire to do better in future.<!--content-->
 
Back
Top