stoiph
 
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>
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,978 • Replies: 0
No top replies

 
 

Related Topics

 
  1. Forums
  2. » Swap Image
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 04/25/2024 at 02:01:21