File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes How Do I Access All of the src Attributes of All of the Images in a Web Page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How Do I Access All of the src Attributes of All of the Images in a Web Page?" Watch "How Do I Access All of the src Attributes of All of the Images in a Web Page?" New topic
Author

How Do I Access All of the src Attributes of All of the Images in a Web Page?

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Hello,

I'm studying JavaScript and I'm stuck on one of my assignments. I'm supposed to write JavaScript code that will output all of the src attributes of all of the img tags on a page. I've written the code, but it only reports on the first image. What am I doing wrong?



Here's a link to my page that I've uploaded to the web: webpage
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You're using document.write wrong.
Nitin Surana
Ranch Hand

Joined: Jan 21, 2011
Posts: 129

Actually, your method works fine. For testing that, simply use an alert instead of a document.write.



Instead of document.write you can try something like this mydiv.innerHTML(mydiv.innerHTML()+img.src+"
");
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Nitin Surana wrote:Actually, your method works fine. For testing that, simply use an alert instead of a document.write.

[code=java]FYI: It is inappropriate to call document.write once the page has been rendered.[/code

Thank you.
 
jQuery in Action, 2nd edition
 
subject: How Do I Access All of the src Attributes of All of the Images in a Web Page?