You are here: irt.org | FAQ | JavaScript | Image | Q1690 [ previous next ]
The following works correctly in Internet Explorer 4+ and Netscape Navigator 6+:
<html>
<head>
<script language="JavaScript"><!--
function swap(target, source) {
if (document.images) {
document.images[target].src = document.images[source].src;
document.images[target].width = document.images[source].width;
document.images[target].height = document.images[source].height;
}
}
//--></script>
</head>
<body>
<form>
<input type="button" value="Swap larger for smaller" onClick="swap('large','small')">
<input type="button" value="Swap larger for smaller" onClick="swap('small','large')">
</form>
<img name="large" src="banner0002.gif">
<img name="small" src="home0.gif">
</body>
</html>