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
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: 688

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: 18127
    
    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: 688

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Do I Access All of the src Attributes of All of the Images in a Web Page?
 
Similar Threads
A simple javascript and html quest
object expected error in IE only
how to call javascript function from jsf
Different image reload in the page when i click in the refresh(f5)
prototype framework with ajax in struts 2 'jsp