Prev Demo
JavaScript
>
Changing The Images
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <h1>Changing the Image</h1> <img src="http://techfunda.com/HTPictures/Generics/5-635898849972807270.JPG" id="myImage" width="100" height="150"> <input type="button" onclick="changeImage()" value="Change" /> <script> function changeImage() { var image = document.getElementById('myImage'); if (image.src.match("635898850094838508.JPG")) { image.src = "/HTPictures/Generics/5-635898849972807270.JPG"; } else { image.src = "/HTPictures/Generics/5-635898850094838508.JPG"; } } </script> <p><strong>Note:</strong> Click on the "Change" button to Change the water bottle in to the soft drink bottle</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output