This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • 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
  • 0
  • 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
Pie
Posts: 20185
26
MySQL Database
  • 0
  • 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
  • 0
  • 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
  • 0
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic