Javascript examples for DOM HTML Element:Image
The src property sets or gets the src attribute of an image.
Set the src property with the following Values
Value | Description |
---|---|
URL | Sets the URL of the image. |
A String, representing the URL of the image.
<!DOCTYPE html> <html> <body> <img id="myImg" src="http://java2s.com/resources/a.png" width="107" height="98"> <button onclick="myFunction()">Test</button> <script> function myFunction() {/*from www . j a v a 2 s .c om*/ document.getElementById("myImg").src = "http://java2s.com/resources/b.png"; } </script> </body> </html>