Javascript examples for DOM:Document images
Document images Collection item(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() {/*ww w .j av a 2s .c o m*/ var x = document.images.item(0).src; document.getElementById("demo").innerHTML = x; } </script> </body> </html>