Reply
Tue 18 Feb, 2014 01:18 pm
I need to make a function with the onclick handler swapTwo() to encapsulate the statements for swapping the source files for the two image elements. The button in the page should call this function when clicked.
ANY help would be great.
<!doctype html>
<!-- swap.html Dave Reed -->
<!-- Web page that swaps two images at the click of a button. -->
<!-- ======================================================== -->
<html>
<head>
<title>Image Swapper</title>
</head>
<body>
<div style="text-align:center">
<h2>Image Swapper</h2>
<p>
<img id="leftImg" src="http://balance3e.com/Images/happy.gif">
<img id="rightImg" src="http://balance3e.com/Images/sad.gif">
</p>
<input type="button" value="Swap images"
onclick="saved=document.getElementById('leftImg').src;
document.getElementById('leftImg').src=
document.getElementById('rightImg').src;
document.getElementById('rightImg').src=saved;">
</div>
</body>
</html>