You are here: irt.org | FAQ | JavaScript | Image | Q223 [ previous next ]
<script language="JavaScript"><!-- function flip() { if (document.images) document.images['image1'].src = 'image2.gif'; } //--></script> <a href="#" onClick="flip();return false"><img src="image1.gif" name="image1" width="100" height="100" border="0"></a>
Or, if you prefer more control over what image is swapped:
<script language="JavaScript"><!-- function flip(name,src) { if (document.images) document.images[name].src = src; } //--></script> <a href="#" onClick="flip('image1','image1a.gif');return false"><img src="image1.gif" name="image1" width="100" height="100" border="0"></a> <a href="#" onClick="flip('image2','image2a.gif');return false"><img src="image2.gif" name="image2" width="100" height="100" border="0"></a>