sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
rakesh19's Avatar

getElementsByTagName


Question posted by: rakesh19 (Newbie) on August 27th, 2008 07:00 PM
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 .
5 Answers Posted
gits's Avatar
gits August 27th, 2008 08:41 PM
Moderator - 3,369 Posts
#2: Re: getElementsByTagName

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
NavnathKale's Avatar
NavnathKale August 31st, 2008 04:19 PM
Newbie - 3 Posts
#3: Re: getElementsByTagName

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 ;  }
Dormilich's Avatar
Dormilich August 31st, 2008 08:56 PM
Expert - 596 Posts
#4: Re: getElementsByTagName

you should use: document.getElementsByTagName('img') (<image> is not a valid tag name)
NavnathKale's Avatar
NavnathKale September 2nd, 2008 06:13 PM
Newbie - 3 Posts
#5: Re: getElementsByTagName

Quote:
Originally Posted by Dormilich
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.
gits's Avatar
gits September 2nd, 2008 09:44 PM
Moderator - 3,369 Posts
#6: Re: getElementsByTagName

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 ;))
Reply
Not the answer you were looking for? Post your question . . .
197,038 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 197,038 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Javascript / DHTML / Ajax Contributors