Javascript examples for Language Basics:HTML
Change the value of the source attribute (src) of an <img> element, if the user clicks on the image:
<!DOCTYPE html> <html> <body> <img id="myImage" onclick="changeImage()" src="http://java2s.com/resources/a.png" width="100" height="180"> <script> function changeImage() {/* w w w . j a v a 2 s.c o m*/ var image = document.getElementById("myImage"); if (image.src.match("bulbon")) { image.src = "pic_bulboff.gif"; } else { image.src = "pic_bulbon.gif"; } } </script> </body> </html>