Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q223 How can I make a different image appear when an image is clicked?

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>

Feedback on 'Q223 How can I make a different image appear when an image is clicked?'

©2018 Martin Webb