• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kaydell Leavitt
Ranch Hand
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using document.write wrong.
 
Nitin Surana
Ranch Hand
Posts: 129
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic