By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,528 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,528 IT Pros & Developers. It's quick & easy.

getElementsByTagName

P: 17
Hi,

I have a set of elements by tag name eg. <img> I want to extract and also identify which one I have taken.

eg.

<a><img src="1.png"/></a>
<a><img src="2.png"/></a>

How do I get 1.png or 2.png .
Aug 27 '08 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,390
loop through the collection and check for the src-attribute ... do you have done anthing already? please post what you have so far ...

kind regards
Aug 27 '08 #2

P: 2
Expand|Select|Wrap|Line Numbers
  1. var objImages = document.getElementsByTagName('image');  for(var imgIndex =0; imgIndex<=objImages.length-1; imgIndex++)  {      var objImage = objImages[imgIndex];      //add your code here to handle objImage image object ;  }
Aug 31 '08 #3

Dormilich
Expert Mod 5K+
P: 8,639
you should use: document.getElementsByTagName('img') (<image> is not a valid tag name)
Aug 31 '08 #4

P: 2
you should use: document.getElementsByTagName('img') (<image> is not a valid tag name)

:) yes I realise that. It was typo!!!. Obviously there is no such element with nodeName image.
Sep 2 '08 #5

gits
Expert Mod 5K+
P: 5,390
not in html ... :) but in XUL for example it is ... certainly a typo and a good catch too to point that out to avoid confusion ... well done ... both of you ;))
Sep 2 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.