Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h1>Javascript Can Change Images</h1>
- <!--Must make id if using JS-->
- <img id="myImage" onclick="changeImage()" src="image1.png" width="100" height="100">
- <p>Click on the image to change it</p>
- <script>
- function changeImage() {
- var image = document.getElementById('myImage');
- if (image.src.match("image1")) {
- image.src = "image2.jpg";
- } else {
- image.src = "image1.png";
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement