Javascript examples for DOM:Document images
Document images Collection [index] - Get the URL of the first <img> element (index 0) in the document:
<!DOCTYPE html> <html> <body> <img src="http://java2s.com/resources/a.png" alt="flower" width="150" height="113"> <img src="http://java2s.com/resources/b.png" alt="flower" width="152" height="128"> <img src="http://java2s.com/resources/c.png" alt="Smiley face" width="42" height="42"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j a v a2 s.c o m var x = document.images[0].src; document.getElementById("demo").innerHTML = x; } </script> </body> </html>