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,499 • Replies: 0
No top replies

 
 

Related Topics

How does one uninstall a program? - Question by Woollcott
Adding a JavaScript 'Copy to Clipboard' - Discussion by BobbyDouglas
JavaScript: OnSelect question - Discussion by neocode
Javascript - Control C textarea script - Discussion by Craven de Kere
2018123 - Question by ibk1995
javascript loops for - Question by vartul agnihotri
 
  1. Forums
  2. » Swap Image
Copyright © 2021 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 06/14/2021 at 03:38:50