Webmonkey
Powered by Atomz.com



Quick Reference:

• Javascript Code Library
HTML Cheatsheet
Special Characters
Color Codes
Browser Chart
Stylesheet Guide
Unix Guide
Glossary
Domain Registries

Reference   JavaScript Code Library

JavaScript is commonly used to change the source of an image (for example, when a user clicks on or mouses over the image in question). The WM_imageSwap() function takes a reference to the original image and a URL for the new image as arguments and then changes the source of the original image to that of the new image.

Usage: WM_imageSwap(originalImage, 'newSourceUrl');
originalImage can be either of the following:

  • A predefined name for the image ('foo', for example, if the image tag includes name="foo"). The name should be a string, so don't forget to enclose it in quotes.
  • An actual object reference (such as window.top.someFrame.myImage). Note, however, that this will produce an error in IE 3 for the Macintosh if you refer to the images array. To use object references without producing errors, use document.myImage in place of document.images['myImage'].

Example: <a href="#" onMouseOver="WM_imageSwap('myImg', 'on.gif');" onMouseOut="WM_imageSwap('myImg', 'off.gif');"><img name="myImg" src="off.gif"></a>

Requires: WM_preloadImages() (optional, but recommended)

License: Webmonkey Public License

Cut, paste, and enjoy!


Feedback  |  Help  |  About Us  |  Contribute  |  Jobs
Advertise  |  Privacy Statement  |  Terms and Conditions

Copyright © 1994-2000 Wired Digital Inc., a Lycos Network site. All rights reserved.