Advertisement
Felanpro

Example

Sep 26th, 2015
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h1>JavaScript Can Change Images</h1>
  6.  
  7. <img id="myImage" onclick="changeImage()" src="http://www.w3schools.com/js/pic_bulboff.gif" width="100" height="180">
  8.  
  9. <p>Click the light bulb to turn on/off the light.</p>
  10.  
  11. <script>
  12. function changeImage() {
  13.     var image = document.getElementById('myImage');
  14.     if (image.src.match("bulbon")) {
  15.         image.src = "http://www.w3schools.com/js/pic_bulboff.gif";
  16.     } else {
  17.         image.src = "http://www.w3schools.com/html/pic_bulbon.gif";
  18.     }
  19. }
  20. </script>
  21.  
  22. </body>
  23. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement