Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <title>Traffic Light Changer</title>
- <a href="javascript:changeLight('mainImage')"><img src="green.jpg"></a>
- <script>
- var mainImage = document.getElementById("mainImage");
- var imageList = ["green.jpg","yellow.jpg","redyellow.jpg","red.jpg"]
- var imageIndex = 0;
- function changeLight() {
- mainImage.setAttribute("src",imageList[imageIndex]
- imageIndex = (imageIndex + 1)
- }
- </script>
- <button onclick "changeLight">Change Light</button>
- <body>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement