My three penny. To change only the images themselves, it can be done as follows. I entered identifiers for the "btn" elements - for the button and "img1" and "img2" - for images.
The advantage of this approach is that the tags are searched once when an event handler is installed, which increases its efficiency. :)
<script> (function () { var btn = document.getElementById("btn"); btn.onclick = function () { var img1 = document.getElementById("img1"); var img2 = document.getElementById("img2"); return function () { var tmp = img1.src; img1.src = img2.src; img2.src = tmp; } }(); })(); </script>
If you wish, you can change the alt attribute in the same way.
tmp = img1.alt; img1.alt = img2.alt; img2.alt = tmp;
The form itself may look like this.
<form name="form1"> <img name="pic" id="img1" src="3.jpg" alt=""> <img name="pic" id="img2" src="2.jpg" alt=""> <input type="button" id="btn" value="Кнопка кнопка"> </form> <script> (function () { var btn = document.getElementById("btn"); btn.onclick = function () { var img1 = document.getElementById("img1"); var img2 = document.getElementById("img2"); return function () { var tmp = img1.src; img1.src = img2.src; img2.src = tmp; } }(); })(); </script>