beautyfiend
07-01-2009, 01:50 PM
Hi, I am trying to swap 2 images over when a button is pressed but something is wrong with my code.
Any help much appreciated!
<html>
<head>
<script type="text/javascript">
function swap_images() {
images=document.getElementsByTagName("img");
images0=images [0].attributes[0].nodeValue;
images1=images [1].attributes[0].nodeValue;
images [1].attributes[0].nodeValue=images0;
images [0].attributes[0].nodeValue=images1;
}
</script>
</head>
<body>
<form id="myform">
<input type="button" value="Switch" onclick="swap_images()" />
</form>
<br /><br />
<img src="HMT STUFF/HMT/images/elvis.jpg" width="219" height="236" alt="Elvis"/>
<img src="HMT STUFF/HMT/images/mj.jpg" width="231" height="236" alt="MJ"/>
</body>
</html>
Any help much appreciated!
<html>
<head>
<script type="text/javascript">
function swap_images() {
images=document.getElementsByTagName("img");
images0=images [0].attributes[0].nodeValue;
images1=images [1].attributes[0].nodeValue;
images [1].attributes[0].nodeValue=images0;
images [0].attributes[0].nodeValue=images1;
}
</script>
</head>
<body>
<form id="myform">
<input type="button" value="Switch" onclick="swap_images()" />
</form>
<br /><br />
<img src="HMT STUFF/HMT/images/elvis.jpg" width="219" height="236" alt="Elvis"/>
<img src="HMT STUFF/HMT/images/mj.jpg" width="231" height="236" alt="MJ"/>
</body>
</html>