Edit This Code:
See Result »
<!DOCTYPE html> <html> <body> <img src="klematis.jpg" alt="flower" width="150" height="113"> <img src="klematis2.jpg" alt="flower" width="152" height="128"> <img src="smiley.gif" alt="Smiley face" width="42" height="42"> <p>Click the button to display the URL of each img element in the document.</p> <button type="button" onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = document.images; var txt = ""; var i; for (i = 0; i < x.length; i++) { txt = txt + x[i].src + "<br>"; } document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
Result: